Search code examples
laravel-5laravel-authentication

How to customize "email" field in Laravel auth?


I'm trying to customize Laravel's authentication fields. I succeeded for the "name" and "password" fields, but not for the "email" field. I still have the error:

SQLSTATE[42S22]: Column not found: 1054 "email" field unknown in where clause.

I tried to rely on this this, but it didn't work. In RegisterController, I changed the create function to the following.

protected function create(array $data)
{
    return User::create([
        'user_pseudo' => $data['name'],
        'user_email' => $data['email'],
        'usr_mdp' => bcrypt($data['password']),
    ]);
}

Solution

  • This error could come from the unique validation of the email field in the validation method. If there's no column name specified it will use the name of the field as the column name.

    Add the correct column name to the rule in which it's supposed to search for the email and this error should be gone:

    RegisterController.php

    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users,user_email'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }