php - Laravel 5.3 Eloquent - How to post data to multiple tables with a form?
459
So far I can only post data to 1 table with a form.
My controller:
public function store(Request $request, Role $role)
{
$role->fill($request->all());
$role->save();
return redirect('/roles');
}
My view:
<div >
<label for="name-input">@lang('role.name')</label>
<input id="name-input" type="text" name="name" value="{{ isset($role) ? $role->name : '' }}" autofocus>
</div>
<div >
<label for="description-input">@lang('role.description_optional')</label>
<textarea id="description-input" name="description" >{{ isset($role) ? $role->description : '' }}</textarea>
</div>
So it perfectly stores thename
anddescription
, but what if I wanted to store data to a second table?
Answer
Solution:
Something like this