Data is not getting stored in database for multiple check box in laravel
Ad
I have created a form, in which I have a list of days to be selected multiple. But those days are not getting stored in database.
here is my controller:
public function store(EventRequest $request)
{
$input = Request::all();
$input['days_of_week'] = Input::get('days_of_week');
Event::create($input);
return redirect('event');
}
and my view is:
@foreach($days as $day)
<ul>
<li>
{!! Form::checkbox("days_of_week[]", $day, null) , $day !!}
</li>
</ul>
@endforeach
when I return Input::get('days_of_week');
it displays the check boxes I select.
How can I store checkbox value along with all the other fields present in form.
Ad
Answer
Ad
Like Jerodev said, you cannot store array to the database. What you can do is serialize the array and store it. Then when retrieving the value, you can unserialize it.
public function store(EventRequest $request)
{
$input = Request::all();
$input['days_of_week'] = serialize(Input::get('days_of_week'));
Event::create($input);
return redirect('event');
}
and you can retrive it like this
$daysOfWeek = unserialize(Event::find(1)->days_of_week);
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad