我在数据库中有四个字段: Profile_id(主键),user_id,First_name,Last_name
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');
}
这只存储First_name和last_name,如何与其他人保存用户ID。
答案 0 :(得分:3)
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');
}
尝试这种方式存储数据