vendredi 4 octobre 2019

Laravel 5.7, API with driver passport, can't add validation on login

I have 2 apps using the same db.

One is in PHP 5.6 and Laravel 5.3, it's an entire Laravel app with views, js, all in Laravel.

The other one in PHP 7.1 and Laravel 5.7 (it's used as an API for a ReactJS app)

In the older one, my LoginController I have rewrite this method of AuthenticatesUsers:

protected function validateLogin(Request $request)
{
    $this->validate(
        $request, 
        [
            'email' => 'required|exists:users,email,active,1|exists:users,email,access_oldmaster,1',
            'password' => 'required'
        ], 
        [
            'email.exists' => 'El nombre de usuario es incorrecto o la cuenta se encuentra deshabilitada.'
        ]
    );
}

This version as in it's config/auth.php this:

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

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],
],

The validation works ok. I'm trying to implement that same validation on the newer version:

'email' => 'required|exists:users,email,active,1|exists:users,email,access_oldmaster,1',

But the newer version, has this driver in the config (remember that this version is an API):

'api' => [
    'driver' => 'passport',

So, I tried to do the same as the older version, to rewrite the LoginController with the same validateLogin method, but the API is not using it.

How could I use that validation in my API?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire