Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jeFFF's avatar
Level 3

Login with credentials, recover field error

Hello there,

I check if a user is active @login with this function :

use Illuminate\Http\Request;

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

It works like a charm but I wonder if it's possible to recover the active field error to display a specific account deactivated message ?

0 likes
2 replies
MichalOravec's avatar

You can overwrite validateLogin in your LoginController

use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

/**
 * Validate the user login request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return void
 */
protected function validateLogin(Request $request)
{
    $validator = Validator::make($request->all(), [
        $this->username() => [
            'required', 'string',
            Rule::exists('users')->where('active', 1)
        ],
        'password' => 'required|string',
    ]);

    if ($validator->fails()) {
        flash('Either you have entered incorrect login information or your account is not active yet.')->error();
    }
}

The flash()function is just flash message from https://github.com/laracasts/flash

jeFFF's avatar
Level 3

I will try that, thanks for your reply ;)

Please or to participate in this conversation.