我使用 Laravel 5.2 框架。
我有一个名为
template
的模型。有用户特定的布局选项。
现在我想轻松获得模板
$template = App\Template::where('userid', Auth::user->id);
但是如果我想添加这些模板,我就会遇到一些问题。
App\Template::create(Request::all());
不起作用,因为请求没有
userid
使用用户 ID 保存新对象的典型方法是什么?
您可以将请求数组与包含用户 ID 的数组合并。像这样:
App\Template::create(array_merge(Request:all(), array('user_id' => Auth::user->id)));