I want to implement two types of login authentication with Ravel 5.

Asked 2 years ago, Updated 2 years ago, 40 views

Creating pages that require login in Ravel 5.0.
Administrative users (Admin) and general users (Users) exist, and the structure and usage are very different, so we divided them into separate tables.
User login uses a slight modification of the authentication function using the standard eloquent driver (authenticated by login ID).
This time, I would like to create a new authentication driver specifically for administrative users, and log in as Admin on certain pages.

Authentication is done with middleware, and User authentication specifies the pages that need authentication in each page controller constructor as follows:

public function__construct()
{
    $this->middleware('auth');
}

Admin authentication is also considered to take the following form:

public function__construct()
{
    $this->middleware('admin-auth');
}

First of all, I made an AdminAuthenticate.php copy of App\Http\Middleware\Authenticate.php and registered it with Kernel.php.

I'm guessing that I'm going to add something like App\Providers\AdminAuthServiceProvider to the config/app.php to expand Auth, but I don't know how to do it.
Is it possible to create a new authentication driver different from eloquent so that it can be switched?
Please let me know if there is a good way.

php laravel

2022-09-30 16:39

1 Answers

Can I just set it to $routeMiddleware in App\Http\Kernel.php?

protected$routeMiddleware=[
    'admin-auth' = > 'App\Http\Middleware\AdminAuthenticate',
];

We manage admin and user permissions in the same way, but we set the role fields in the users table and separated them by numbers, and the above authentication works fine.

Please understand that we are not able to verify it because we do not manage it in a different table like Nuages built.


2022-09-30 16:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.