我创建了一个表单,其中列出了多个选择日期。 但那些日子并没有存储在数据库中。
这是我的控制器:
public function store(EventRequest $request) { $input = Request::all(); $input['days_of_week'] = Input::get('days_of_week'); Event::create($input); return redirect('event'); }我的观点是:
@foreach($days as $day) <ul> <li> {!! Form::checkbox("days_of_week[]", $day, null) , $day !!} </li> </ul> @endforeach当我返回Input::get('days_of_week'); 它显示我选择的复选框。
如何存储复选框值以及表单中存在的所有其他字段。
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> @endforeachwhen 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.
最满意答案
像Jerodev所说,你不能将数组存储到数据库中。 你可以做的是序列化数组并存储它。 然后在检索值时,可以对其进行反序列化。
public function store(EventRequest $request) { $input = Request::all(); $input['days_of_week'] = serialize(Input::get('days_of_week')); Event::create($input); return redirect('event'); }你可以像这样回复它
$daysOfWeek = unserialize(Event::find(1)->days_of_week);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);更多推荐
发布评论