Update the Auth Email Database Field Name In Laravel 9+

Based off some quick research this seemed a little easier in previous versions of Laravel, but after the departure of the LoginController and the adoption of the Request classes things were adjusted some. This is especially useful if you are implementing Laravel on top of an already existing database/codebase, which is my use case.

There seems to be two paths of least resistance

  1. `LoginRequest` - This is the one I chose to use.

Before--

public function authenticate()
{
    $this->ensureIsNotRateLimited();

    if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
        RateLimiter::hit($this->throttleKey());

        throw ValidationException::withMessages([
	        'email' => trans('auth.failed'),
        ]);
    }

    RateLimiter::clear($this->throttleKey());
}

After --

public function authenticate()
{
    $this->ensureIsNotRateLimited();
    
    $credentials = [
    	'new_email_field_name' => $this->email,
        'password' => $this->password,
    ];

    if (! Auth::attempt($credentials, $this->boolean('remember'))) {
        RateLimiter::hit($this->throttleKey());

        throw ValidationException::withMessages([
	        'email' => trans('auth.failed'),
        ]);
    }

    RateLimiter::clear($this->throttleKey());
}

2. Login View

You can update the name attributes on the field to match your database value, but you still will have to make a change to the LoginRequest class, which is why I opted to keep the view the same and make the change in the LoginRequest alone.

⚠️
This does not work for the password field. There is an different way to handle that entirely.