ahmadbadpey's avatar

Two different models for authentication in larvel 5.4

Suppose I have two different models and tables named user and company.

As you know laravel uses User model to manage Authentication. but beacause I have two different model I want can manage them separately.

I'm using laravel 5.4 and I do not know how can do that.

0 likes
1 reply
robrogers3's avatar

If a company can login, as an entity, and you want to apply different rules for authentication, then you need to write one. It takes several steps.

blech, this would be a long answer.

take a look at: https://laracasts.com/discuss/channels/laravel/authentication-return-column-id-in-where-clause-is-ambiguous-because-a-globalscope?page=1#reply-376860

there are links at the bottom.

Now this only gives you the what's in general.

You'll need to create another guard for auth.php, routes, controllers, and the Company Model needs to implement use Illuminate\Foundation\Auth\User as Authenticatable for your company model.

hope this get you started. ping me if you need more help.

Please or to participate in this conversation.