I am currently building my first laravel application for a school project. I am using Laravel Jetstream, which might now was the best choice but its too late to change that now.
In the CreateNewUser.php File after the Validation the "create"-function does the following:
return User::create([...]);
I changed it to
if(condition) {
$user = new User([...]);
$user->save();
return $user;
} else {
return view('error);
}
I am now facing the problem that in case of the condition not applying, laravel gives me the following error:
This does make sense to me, but after a few hours of looking through the code and browsing the interet, I havent been able to figure out how I can customize the code so I can return an error page.
I would be very happy if anyone of you could help me as I am now quite sure how to go on at this point.
Edit: After reviewing the question a second time, I noticed its maybe not clear why I am doing it that way. My Problem is, that I need to sync the user over a pivot table with a school after creating it. Maybe there is also a way to do that while creating the user? If there is, please let me know.
You could likely sync your user of the to the pivot table in RegisteredUserController.php
after the $user
returned before the redirect to login:
public function store(Request $request,
CreatesNewUsers $creator): RegisterResponse
{
event(new Registered($user = $creator->create($request->all())));
//use the newly created $user here
$this->guard->login($user);
return app(RegisterResponse::class);
}