与 userid 相等的添加对象

问题描述 投票:0回答:1

我使用 Laravel 5.2 框架。

我有一个名为

template
的模型。有用户特定的布局选项。

现在我想轻松获得模板

$template = App\Template::where('userid', Auth::user->id);

但是如果我想添加这些模板,我就会遇到一些问题。

App\Template::create(Request::all());

不起作用,因为请求没有

userid
使用用户 ID 保存新对象的典型方法是什么?

php laravel eloquent
1个回答
2
投票

您可以将请求数组与包含用户 ID 的数组合并。像这样:

App\Template::create(array_merge(Request:all(), array('user_id' => Auth::user->id)));
© www.soinside.com 2019 - 2024. All rights reserved.