0

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?

1
  • Welcome to SO .. .you can create your own auth system based on session or cookies and create own middleware to protect Commented May 4, 2021 at 4:54

1 Answer 1

0

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';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.