Hi everyone,
so, I have a bunch of users that have different user account status (not activated, activated, disabled) and user roles (admin, regular user, junior etc.)
Each one of them should have different stuff available to them: different items in the menu, different buttons visible on the rest of the app.
Also, I don't want to allow them to access part of the site that they shouldn't be able to just by typing the URL.
I have created a middleware, UserRoleChecker, and added it to all my routes like this:
//Middleware
public function handle(Request $request, Closure $next)
{
if (auth()->check() && auth()->user()->user_status == 0) {
return redirect('profile');
}
return $next($request);
}
//Routes
Route::get('/profile', 'App\Http\Controllers\UsersController@ShowLoggedInUserProfile')->middleware(['auth','UserRole'])->name('profile');
But I would love to check if this is the right way to implement this controls. Should I also add some controls to every controller or even blade template for this? Is this even enough to make what I need?
Also - this exact code I posted gives me an endless redirect error in the browser - how can I get around that? The only solution I found is to remote UserRole from middleware in the Profile route, but that means no controls, right?