[英]Laravel 5.3 Eloquent - How to post data to multiple tables with a form?
So far I can only post data to 1 table with a form. 到目前为止,我只能使用表单将数据发布到1个表中。
My controller: 我的控制器:
public function store(Request $request, Role $role)
{
$role->fill($request->all());
$role->save();
return redirect('/roles');
}
My view: 我的观点:
<div class="form-group">
<label for="name-input">@lang('role.name')</label>
<input id="name-input" type="text" name="name" class="form-control" value="{{ isset($role) ? $role->name : '' }}" autofocus>
</div>
<div class="form-group">
<label for="description-input">@lang('role.description_optional')</label>
<textarea id="description-input" name="description" class="form-control">{{ isset($role) ? $role->description : '' }}</textarea>
</div>
So it perfectly stores the name
and description
, but what if I wanted to store data to a second table? 因此,它完美地存储了
name
和description
,但是如果我想将数据存储到第二张表怎么办?
Something like this 像这样
$second = new SecondTableModel();
$second->fill($request->all());
$second->save();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.