Home > Software design >  How to redirect to another page in Laravel 8 immediately after authorization?
How to redirect to another page in Laravel 8 immediately after authorization?

Time:04-13

In RouteServiceProvider wrote public const HOME = '/ welcome'; But directs here only if the user is not authenticated. And I need to send here right after registration or authorization (now redirects to the root directory "/".

CodePudding user response:

In your LoginController (if you are using laravel authentification package) you can set the attribute $redirectTo as the destination.

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/dashboard';
//...
}

It is fairly commented and self explanatory by default on installation.

CodePudding user response:

You can use MiddleWare to check if the user registered or even already loggedin this is one example :

public function handle(Request $request, Closure $next)
{
    if(Session()->has('loginId') && (url('login')==$request->url()|| url('registration')
    ==$request->url())){
        return back();
    }
    return $next($request);
}
  • Related