Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in Handler Class - Laravel

I am using Laravel 5.5 and trying to implement multi authentication for users and admin. I am getting this error when i try to call admin login form in browser.

Error :

Declaration of App\Exceptions\Handler::unauthenticated($request, App\Exceptions\AuthenticationException $exception) should be compatible with Illuminate\Foundation\Exceptions\Handler::unauthenticated($request, Illuminate\Auth\AuthenticationException $exception)

Here is my unauthenticated function in app/Exceptions/Handler:

 protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }
        $guard = array_get($exception->guards(), 0);
        switch ($guard) {
            case 'admin':
                $login = 'admin.login';
                break;
            default:
                $login = 'login';
                break;
        }
        return redirect()->guest(route($login));
    }

Please help me to resolve this issue.

like image 870
MA-2016 Avatar asked Sep 21 '17 09:09

MA-2016


1 Answers

You forgot to add use Illuminate\Auth\AuthenticationException at the top of your file

like image 121
Nerea Avatar answered Oct 13 '22 17:10

Nerea