2 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊
使用$request->validate()可能會(huì)有問(wèn)題。如果驗(yàn)證失敗,它會(huì)嘗試返回到上一頁(yè),這并不總是我們想要的。嘗試這樣做。
// Auth Specialist
$user = Auth::user();
$data => $request->input(); //returns array of all input values.
// You might want to use only() instead so as to specify the keys you need
// Data Specialist Validate
$rules = [
'first_name' => 'nullable|string',
...
'postal_code' => 'nullable|integer',
]);
$validation = validator($data, $roles);
if($validation->fails()) {
// do what you wish with the error
return back()->withErrors($validate->errors());
//return response($validation->errros());
}

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊
改變創(chuàng)造
if (is_null($user->profile_settings())){
$user->profile_settings()->create($data);
}
或更改為 firstOrCreate(我對(duì)此選項(xiàng)不太有信心)
$profile = $user->profile_settings()->firstOrCreate($data);
$profile->save();
那么你不需要查詢關(guān)系并且可以刪除 if 語(yǔ)句
- 2 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)