hiddenicon
hiddenicon

Reputation: 581

Laravel 5.4 additional Auth parameters

I have added an email verification to the register process with Laravel 5.4. I am using the built-in Auth configuration as well. I want to now add a "verified" parameter to the authentication process. This used to work in earlier versions of 5.x, but I can't get it to work now.

Editing this file:

project\vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php

I would normally add the "verified" portion of the Login validation.

protected function validateLogin(Request $request)
{
    $this->validate($request, [
        $this->loginUsername() => 'required', 
                    'password' => 'required', 
                    'verified' => 1,
    ]);
}

This doesn't appear to be working in 5.4 now. I can login without verifed being true. Is there another way I can change this without touching any back-end classes or traits? Can I do this in the LoginController instead to make it easier to persist across Laravel upgrades?

Upvotes: 0

Views: 1703

Answers (1)

Sandeesh
Sandeesh

Reputation: 11906

Yes you can do it. Add this to your LoginController

use Illuminate\Http\Request;

protected function credentials(Request $request)
{
    return array_merge($request->only($this->username(), 'password'), ['verified' => 1]);
}

Never modify the core files. You can always override the core class methods in your controller.

Upvotes: 1

Related Questions