barryw33's avatar

firing a redirect from an event

I have a reset_password field within my users table that is set to '1' when a user account is created . When a user logs in I check this field and if set to '1' within an event. I want to redirect from the event if the field is set to '1'.

I have tried:

return redirect()->route('user/change_password');

and in my routes file I have set Route::get('user/change_password', 'UserController@resetpasswordform');

but this returns an error of: InvalidArgumentException in UrlGenerator.php line 306: Route [user/change_password] not defined.

I have also tried this return redirect()->action('UserController@resetpasswordform');

but this is just ignores the redirect and logs the user in. I have set a dd('hello'); within the method but this does nothing.

I have tried changing the redirect for an authenticated user and if the field is not set to 1 then follows this redirect, but if the field is set to 1 it ignores this.

I am at a loss as to the route that this redirect is taking

any help greatly appreciated

0 likes
2 replies
bobbybouwmann's avatar
Level 88

Event don't work like that. An event is called as a background task and therefore the redirect will never fire in the controller.

You need to do that check in your controller and based on that redirect the user!

2 likes
barryw33's avatar

I copied the postLogin class to my AuthController and theredirect to the method

if (Auth::attempt($credentials, $request->has('remember'))) { if(Auth::user()->reset_password=='1'){ return redirect()->action('UserController@resetpasswordform'); } return $this->handleUserWasAuthenticated($request, $throttles); }

Please or to participate in this conversation.