1 回答
TA贡献1772条经验 获得超6个赞
首先你不需要像这样在你的动作中注入User模型store
public function store(User $user, Request $request)
您可以在hospital控制器的store操作中使用类似以下代码的事务
public function store(Request $request)
{
$request->validate([
'name' => 'required|max:255',
'email' => 'required|max:255|unique:users',
'password' => 'required|min:8',
]);
DB::transaction(function () use($request){
// $user = User::create($this->transformForm($request));
$user = User::create([
'name' => $request->input('name'),
'email' => $request->input('email'),
'password' => $request->input('password'),
]);
// update or insert here
Hospital::Create([
'user_id' => $user->id,
'companyname' => $request->input('companyname'),
'adress' => $request->input('adress'),
'postalcode' => $request->input('postalcode'),
'residence' => $request->input('residence'),
// 'phonenumber' => $request->input(), //missing in your form
// 'mailadress' => $request->input() // missing in your form
]);
});
return //redirecto to a success page or somewhere else
}
- 1 回答
- 0 关注
- 99 浏览
添加回答
举报