Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用eloquent在Laravel中存储具有用户id的输入数据?_Laravel_Eloquent_Laravel 5.5 - Fatal编程技术网

如何使用eloquent在Laravel中存储具有用户id的输入数据?

如何使用eloquent在Laravel中存储具有用户id的输入数据?,laravel,eloquent,laravel-5.5,Laravel,Eloquent,Laravel 5.5,我在数据库中有四个字段: 配置文件id(主键)、用户id、名字、姓氏 public function store(Request $request) { $this->validate($request, [ 'first_name' => 'required|max:50', 'last_name' => 'required|max:50', ]); $user_id= Auth::user()->id;

我在数据库中有四个字段: 配置文件id(主键)、用户id、名字、姓氏

 public function store(Request $request)
 {
    $this->validate($request, [
        'first_name' => 'required|max:50',
        'last_name' => 'required|max:50',
    ]);
    $user_id= Auth::user()->id;
    $postdata = $request->all();
    profile::create($postdata);
    return redirect('profile');
}
这只存储名字和姓氏,以及如何与其他人一起保存用户id

public function store(Request $request)
{
$this->validate($request, [
    'first_name' => 'required|max:50',
    'last_name' => 'required|max:50',
]);
$data['user_id'] = Auth::user()->id;
$data['first_name'] = $request['first_name'];
$data['last_name'] = $request['last_name'];
profile::create($data);
return redirect('profile');
}
尝试这种方式,它将存储您的数据


尝试这种方式,它将存储您的数据

如果您失败,您需要在模型上指定
$filleble
属性。我已经编写了,我想知道正确的查询,如profile::create($postdata)您需要开始阅读文档,它就在那里。您失败了,您需要在您的模型上指定
$filleble
属性。我已经编写了,我想知道正确的查询,如profile::create($postdata)您需要开始阅读文档,它就在那里。