'How to create custom authentication in laravel 8?

How to create custom authentication in laravel 8 with a preexisting table (but with table name Users_system not Users) and this table (Users_system) is full of data and does not have the same fields as Users for laravel?



Solution 1:[1]

For beginners in Laravel who want to set up an admin panel or dashboard with mail based authentication and basic CMS features WITHOUT using any Laravel packages. AdminLTE default integrated. Just download LaraShade from: https://github.com/agni-s-chakraborty/larashade

Solution 2:[2]

Its not necessary to have same fields in your database. If you want to create a new model for new table, create UserSystem model and replace all the App\User instances with App\UserSystem model.

If you want to use existing model, just change the table name in the App\User model.

If you have different user name or any authentication credentials, you need to move Illuminate\Foundation\Auth\AuthenticatesUsers class code to App\Http\Controllers\Auth\LoginController.

Following are the code segments that you need to change there.

protected function validateLogin(Request $request)
{
    $request->validate([
        $this->username() => 'required|string',
        'password' => 'required|string',
    ]);
}

protected function credentials(Request $request)
{
    return $request->only($this->username(), 'password');
}

//Mention your username here
public function username()
{
    return 'user_name';
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Agni Sankar Chakraborty
Solution 2 Kajan Thadsanamoorthy