public function store(UserRequest $request)
{
//开启事务
\DB::transaction(function () use ($request) {
$role = $request->input('roles');
//保存用户
$user = User::create($request->except(['_token', 'roles', 'password_confirmation']));
//赋予角色
$result = $user->assignRole($role);
if ($result) {
alert()->success('用户添加成功!');
} else {
alert()->error('用户添加失败!');
}
return redirect()->route('user.index');
});
}
请问各位大神如何才知道,事务执行成功?我这样子做redirect无效 数据是已经保存了!