MrFiliper
2 years ago
143
8
Lumen

Method attempt does not exist or Auth guard driver [api] is not defined.

Posted 2 years ago by MrFiliper

I use Lumen 5, and I'm having trouble with using authentication.

I have uncommented

$app->register(App\Providers\AuthServiceProvider::class);
$app->withFacades();
$app->withEloquent();

in app.php but authentication not work /

    public function postLogin(Request $request)
    {
        $this->validate($request, [
            'email'    => 'required|email',
            'password' => 'required',
        ]);

        $credentials = $request->only('email', 'password');

        if (Auth::attempt($credentials, $request->has('remember'))) {
            return ['result' => 'ok'];
        }

        return ['result' => 'not ok'];
    }

If I create a request to /login with params need to succesful request, display error:

Method attempt does not exist.

Ok, next I create new auth.php config

<?php

return [
    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],

    'guards' => [
        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => \App\User::class
        ]
    ]
];

and display next error: Auth guard driver [api] is not defined.

Why? The api guard is defined in the config?!

Thanks for replay!

Please sign in or create an account to participate in this conversation.