I am experiencing this error when trying to register a user. The registration goes through i suppose because the data is inserted into the database but then it throws up this error instead of redirecting to dashboard.
I am kind of new to this so I am not sure where the error is coming from. I already tried searching for solutions online but not coming across any.
Here is my registerController
protected $redirectTo = RouteServiceProvider::HOME;
protected function redirectTo()
{
$user = auth()->user();
if ($user->role == 'guest') {
return route('guest.profile');
} else if ( $user->role == 'superadmin' ) {
return route('superadmin.home');
}
}
public function __construct()
{
$this->middleware('guest');
}
protected function validator(array $data)
{
return Validator::make($data, [
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:6', 'confirmed'],
]);
}
protected function create(array $data)
{
return User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
Finally seen my error. Was supposed to add an else block to the redirect method. Added it and error went away.
protected function redirectTo()
{
$user = auth()->user();
if ($user->role == 'guest') {
return route('guest.profile');
} else if ( $user->role == 'superadmin' ) {
return route('superadmin.home');
} else {
return route('home');
}
}
Thanks all for the help