samedi 21 septembre 2019

How to configure the redirect URL when session timeout - Laravel 5.8?

When session timeout - I keep redirect to : http://bheng.test/login

that leads to crashing

How do I overwrite this behavior to redirect to : http://bheng.test instead ?

This is my AuthMiddleware.php

<?php

namespace App\Http\Middleware;
use Closure, View;
use Illuminate\Contracts\Auth\Guard;

class Authenticate {

    /**
     * The Guard implementation.
     *
     * @var Guard
     */
    protected $auth;


    /**
     * Create a new filter instance.
     *
     * @param  Guard  $auth
     * @return void
     */
    public function __construct(Guard $auth)
    {
        $this->auth = $auth;
    }

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if ($this->auth->guest())
        {
            if ($request->ajax())
            {
                return response('Unauthorized.', 401);
            }
            else
            {
                return redirect()->guest('/');
                // return response('Unauthorized.', 401);
                // return View::make('layouts.share.errors.404');
            }
        }

        return $next($request);
    }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire