@johnw65 Create a middleware, that checks if the user has a certain role or not and add it to your routes.
https://laravel.com/docs/8.x/middleware#defining-middleware
https://laracasts.com/series/laravel-6-from-scratch/episodes/54
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm relatively new to Laravel, and I have a following question.
Currently, different users have access to different applications. I know it's a relatively general question, but what is the best method to make sure that an user can only access their authorized application. I have seen codes where in the constructor method of a controller, they check to see whether an user has authorized access, but not sure whether that is the best approach.
I do have an user roles table which lists all of the applications that an user have access to and also whether it's read or read/write access.
Thanks in advance.
@johnw65 Policies have methods to determine whether a user can view, update, delete, etc a particular model: https://laravel.com/docs/8.x/authorization#writing-policies
So you can use a policy to first check if a user can actually view an application based on their role/assigned applications, and then use that policy in your Blade views to conditionally show things like edit buttons:
@can('update', $application)
<a href="{{ route('application.edit', compact('application')) }}">
{{ __('Edit') }}
</a>
@endcan
Please or to participate in this conversation.