dimanche 17 mai 2020

Laravel Unable to login first time with custom login

I create a login with laravel. But I can't login first time. This is my code.This is my LoginController.

public function __construct() {
    $this->middleware('guest')->except('logout');
    $this->middleware('guest:myguard')->except('myLogut');
}

This is myLogut() function.

public function myLogut(Request $request) {
    Auth::guard('myguard')->logout();
    return Redirect::to('/mylogin');
}

This is login function

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

    if (Auth::guard('myguard')->attempt(['email' => $request->email, 'password' => $request->password], $request->get('remember'))) {

        return redirect()->intended('/mylogin');
    }
    return back()->withInput($request->only('email', 'remember'));
}

This is my guard code

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'myguard' => [
        'driver' => 'session',
        'provider' => 'myguard',
    ],
],

and providers

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

],


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire