so I have a form with a select option inside it, and I’m trying to get the choice of the user and then insert it into the table and then database, but it doesn’t seem to be working. Here is the code I thought was necessary to understand the problem, if there is anything else you need please let me know!
HTML
<form method="POST" action="{{ route('createEvent') }}">
<label for="is_private">Privacy</label>
<select id="is_private" name="is_private" required autofocus>
<option value="" disabled selected>-- select one --</option>
<option value="is_public">Public</option>
<option value="is_private">Private</option>
</select>
</form>
EventController.php
if (null !== $request->input('is_private')) {
$event->is_private = 'true';
}
else {
$event->is_private = 'false';
}
The problem is that it’s always returning with $event->is_private = 'true';
and I don’t know why…
Thanks alot for any help you may provide!
3
Answers
You need to use following code. I think you want that if user select is_private option then $event->is_private is true other wise false.
Hmm.. I would try something like:
That should do it in one line and be an actual Boolean type.