PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 4, 2022

[FIXED] Firing a redirect from a Laravel event

 March 04, 2022     events, laravel-5, redirect     No comments   

Issue

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.


Solution

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);
}


Answered By - Barry Watts
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing