When to use ?
We ever wonder in form selection or dropdown we need to get field 'name' from other table .
Example situation . Each patron should has one patron profile that is in our modal patron we should use belongsTo function whereby patron profile should use hasMany function since one patron profile can have many patrons.
In our form selection we should consider pass the table name with eloquent pluck from our controller. However we need to remind the only thing should be save when using pluck is "ID". Here is the example :
Controller
$data = array(
'breadcrumb' => array('Setting', 'Library' ,'Create Patron Profile'),
'submenu' => 'setting.library.library_navbar',
'content' => 'setting.library.patronprofile.form',
'title' => 'Profile Form',
'settingtitle' => 'Library',
'toggle' => 'patron_profile',
'typeselection' => $typeselection,
'profileselection' => ProfileSetting::pluck('name', 'id')->all(),
'subjectselection' => $subjectselection,
'type' => 1,
);
return view('layouts.setting_template')->with($data);
View
{!! Form::MultiDropdown('profile_id', $profileselection, (!empty($patron->profile_id)) ? $patron->profile_id: '','class="select2-form" required') !!}
No comments:
Post a Comment