Authentication with two different tables

Asked

Viewed 952 times

9

I need to do two authentications, one for clients another for administrators, so I have to have two instance of auth; how to do this in Laravel, where I have a client table and another for administrators?

  • why it has 2 tables?

  • one of clients and the other of administrators.

  • I believe that the ideal is for you to create a specific table for login, which will be "linked" either with customers or with administrators (specialization). So it looks better even working, because imagine that in one table the name of the user is 'name', and in another 'full name', you will have to fill your system of if (or create accessors, but still).

2 answers

8


The most practical method is to configure the authentication on the route where needed:

Config::set('auth.model', 'Admin');

or set to a URI standard

if ($request->is('admin*'))
{
    Config::set('auth.model', 'Admin');
}

Thus, the Model Admin shall be responsible for authentication.

1

I believe it is the case to create a new Auth class Illuminate\Auth\Guard and some Facades, to replicate the Auth component. Then you would, for example, an authentication using Auth::attempt() and one using your authentication, MeuAuth::attempt().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.