0

I generated a different table to store users for my website. Name of the table is tblusers. I am registering new users with a controller method register(), in which i added this code

public function register(){
    return User::create([
        'User_Email' => 'test@example.com',
        'User_UserName' => 'test@example.com',
        'User_Password' => bcrypt('123'),
        'User_Address' => 'ABCD....',
        'User_IsActive' => 1,
        'User_FullName' => 'Burhan Ahmed',
        'User_AppID' => 1,
        'User_IsVerified' => 1
    ]);
}

It adds above dummy data successfully in Database. Then i tried to login with above given credentials using below code:

dd(Auth::attempt(['User_UserName' => 'test@example.com', 'User_Password' => '123']));

But above statement always returns false, Why? Am i missing something. I tried to pass actual bcrypt code instead '123' in above array it returns the same result always. Below is my Model Class

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\DB;

//class User extends Authenticatable
class User extends Authenticatable
{
    use Notifiable;
    protected $table = 'tblusers';
    protected $primaryKey = 'User_ID';
    public $timestamps = false;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'User_UserName', 'User_Email', 'User_Password', 'User_Address', 'User_FullName', 'User_IsActive', 'User_IsVerified'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'User_Password'
    ];
}

I am using Laravel 5.4, i followed all the authentication steps but not matter what i pass it always return false.

tereško
  • 58,060
  • 25
  • 98
  • 150
DIGITAL JEDI
  • 1,672
  • 3
  • 24
  • 52

1 Answers1

1

if You want to Change the default table of login folow the steps

For Example You are Changing it to login_table

Step1:

change the table property in User.php (User Model)

/**
 * The table associated with the model.
 *
 * @var string
 */
protected $table = 'login_table';

Step1:

IF YOU ARE BEGGINER

Now You need to change the table name users to login_table

IF PROJECT IS TEAM COLLBRATION MAKE THE MIGRATION WITH login_table

php artisan make:migration create_login_table_table

and add the columns available in the users table

Step3:

Now open the file app\Http\Controllers\Auth\RegisterController.php

You will find method validator as

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

Now You need to change unique:users to unique:login_table

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

Hope it helps and it works fine for me @ Md.Sukel Ali

Comment if it not works

ManojKiran A
  • 5,896
  • 4
  • 30
  • 43