eijinaal's avatar

Laravel 5.1 multiple Login

I am currently working on laravel 5.1 and i have implemented laravel's default auth for admin panel login. Now my application need front-end login for general user also. How can i do this ? For example. www.domain.com/admin (This is login page for admin) www.domain.com/login (This is login page for general Users) for both these pages i need separate login.

0 likes
14 replies
eijinaal's avatar

Hello tomo_pongrac,

Is any simple way is available for this, that needs less configuration.

eijinaal's avatar

Are there any major differences in 5.1 and 5.2 ?

chris.hearn01@ntlworld.com's avatar

@eijinaal If your application is quite small, then you may find it easier to add an extra column to the Laravel user model e.g. 'Role'. Then have everyone login using standard Laravel methods, and test the $user->role value to redirect users that are not value 'admin' away from your admin pages. Also write a simple isAdmin() function to help in this, or to include extra "admin" bits in your views...

Not as fancy as the previous suggestions, but for smaller apps it will be understandable and work without too much change to standard Laravel install. HTH

tylernathanreed's avatar

@eijinaal Here's a package that I'm working on: https://github.com/tylernathanreed/laravel-auth

It's literally just Multi-Auth from Laravel 5.2 refactored and dropped into 5.1.

I've actually gotten this to work in an existing 5.1 project, so I know that it does the basics. If you have any troubles setting it up, let me know. This package is still early in its development, so any feedback would be appreciated. I'm in the same boat as you, I needed Multi-Auth in 5.1, hence why I created the package in the first place.

I'm actively making any changes to this if any issues arise, so I'll definitely help with any problems you might have.

fikri1510's avatar

Hi @tylernathanreed , I was trying to implement your package in my project, but no luck. I followed the steps as described on github and ended up confusing me. I was stuck on Middleware, for example like in class RedirectIfAuthenticated, and I got error BindingResolutionException in Container.php line 749: Target [Reed\Auth\Contracts\Guard] is not instantiable. Do you have any complete sample for implementing the multi auth using your package for laravel 5.1?

Thanks

martinbean's avatar

@eijinaal You should have one User model and users table, and then user “levels”. Have one login endpoint and you can then check whether the authenticated user’s an administrator or not, and use middleware to restrict their access.

tylernathanreed's avatar

@fikri1510 That's because you're still using the 5.1 RedirectIfAuthenticated Middleware. You need to be using the one from 5.2.

Please or to participate in this conversation.