I am imploding multiple id of subject table via selecting it and saving it in Users table , i am successully saving the data in users table but when i am trying to edit the the user by exploding it subject field is not showing in dropdown..
imploding it like:1,2,3 i want all selected subject of above id in dropdown
Saving the data like this
if(is_array($request->subject)){
$item->subject = implode(',', $request->subject);
Add function to show subject list
public function editForm($id)
{
$item = Users::findOrFail($id);
$subjects = Subject::pluck('subject_title','id');
$item->subject = explode(',', $item->subject);
return view('users.form',$data,compact('item','subjects'));
}
my form dropdown
{!! Form::select('subject[]', $subjects, !empty($item->subject) ? $item->subject : explode(',',old('subject')) ,['class' =>'form-control ' ,'required'=>'true','multiple'=>'true']); !!}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire