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

flashery's avatar

Changing default columns and tables in Laravel Auth 5.2

Ok I am having this problem for a week now. I am following the naming convention of our company in creating Schema for Tables and Columns. This means that I need to modify the default columns and tables use in Laravel Auth 5.2.

I followed the instruction found online. I didn't change the config/auth.php

Our database is MS SQL

My migration script:

     Schema::create('Admins', function (Blueprint $table) {
                $table->increments('Id');
                $table->string('Email')->unique();
                $table->string('Password');
                $table->string('RememberToken')->nullable();
                $table->timestamp('CreatedAt');
                $table->timestamp('UpdatedAt');
            });

My routes:

    Route::auth ();
    
    Route::get ('/', 'HomeController@index');
    Route::get ('/home', 'HomeController@index');

Overriding the defaults in User Model

  1. Specify the table in User model

    ....public $table = 'Admins';

  2. Using my own timestamp column so I disable the default

    ....public $timestamps = false;

  3. Specify primary key use in my table

    ....protected $primaryKey = 'Id';

  4. Specify fillable and hidden fields

   protected $fillable = [
                'Email', 'Password', 'CreatedAt', 'UpdatedAt'
        ];
    
   protected $hidden = [
                'Password', 'RememberToken',
        ];
  1. Overriding more
     // Override required, otherwise existing Authentication system will not match credentials
        public function getAuthPassword ()
        {
            return $this->Password;
    
        }
    
        // Override required, otherwise existing Authentication system will not match credentials
        public function getRememberToken ()
        {
            return $this->RememberToken;
    
        }

Overriding the defaults in AuthController

  1. Login method
 public function postLogin (Request $request)
    {
        $this->validate ($request, [
                'Email' => 'required|email', 'Password' => 'required',
        ]);

        $credentials = $request->only ('Email', 'Password');

        if ($this->auth->attempt ($credentials, $request->has ('remember')))
        {
            return redirect ()->intended ($this->redirectPath ());
        }

        return redirect ($this->loginPath ())
                        ->withInput ($request->only ('Email', 'remember'))
                        ->withErrors ([
                                'Email' => $this->getFailedLoginMessage (),
        ]);

    }

Registration is fine. The problem is when I am trying to login. It gives me this error "These credentials do not match our records". I am pretty sure the login credentials is right because the password is just "123456".

What am I missing? Please help

0 likes
0 replies

Please or to participate in this conversation.