2 回答
TA贡献1812条经验 获得超5个赞
public function save(Request $request)
{
try{
Ticket::create([
'user_id' => Laptop::where('SN', $request->SN)->first()->user_id,
'laptop_id' => Laptop::where('SN', $request->SN)->first()->id,
'title' => $request->title,
'body' => $request->body,
'laptop_ww' => $request->laptop_ww
return view(your_address, "successfully saved");
]);
}catch(Exception ex){
return view(your_address, "Custom error here");
}
}
TA贡献1862条经验 获得超7个赞
试试下面 -
$laptop = Laptop::where('SN', $request->SN)->first();
if(null === $laptop){
throw new Exception('No laptop found with SN'.$request->SN);
}
if(null === $laptop->user_id){
throw new Exception('Laptop with SN:'.$request->SN.' does has any user'.);
}
Ticket::create([
'user_id' => $laptop->user_id,
'laptop_id' => $laptop->id,
'title' => $request->title,
'body' => $request->body,
'laptop_ww' => $request->laptop_ww
]);
您将保存查询并处理错误。
- 2 回答
- 0 关注
- 100 浏览
添加回答
举报