Search on the forum. There is a bunch of discussions on this topic. Do not go with anything complex, just place the role or type column on users table and there is no need for 3 different types of authenticated users. They are all users of your system, they just have different permissions based on a role/type.
Authentication for 3 types of users
I wanna build authentication for 3 types of users admin, user, business and I dont know if I should build that on my own or I should use a package for this task. Option 1 is to build it like so:
https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/16
but it feels like reinventing the wheel.
Option 2 is to use one of these packages:
https://github.com/JosephSilber/bouncer
https://github.com/spatie/laravel-permission
But I am concerned using such packages because what if support runs out? Any advice?
I guess admin has more premissions than business so admin can access everything?
// business middleware
public function handle($request, Closure $next)
{
$user = $request->user();
if ($user->isBusiness() || $user->isAdmin()) {
return $next($request);
}
return redirect('home');
}
// admin middleware
public function handle($request, Closure $next)
{
if ($request->user()->isAdmin()) {
return $next($request);
}
return redirect('home');
}
// routes
// where you want business and roles with greater permissions to have access then just put business middleware
Route::group(['middleware' => ['business']], function () {
// where you want admin to have access then just put admin middleware
Route::group(['middleware' => ['admin']], function () {
Do not forget auth middleware.
There are also other ways to do this, but this is the cleanest and easiest so you do not forget anything to add.
Please or to participate in this conversation.