Courses

Vue Inertia + Laravel 11: From Scratch

User Roles and Permissions Protection

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Passing user permissions via Laravel Inertia Middleware
- Conditionally rendering UI elements based on user permissions
- Implementing back-end permission checks using Gates and Policies
- Creating user-specific permission attributes in the User model
- Protecting routes and controller actions with authorization checks

In this lesson, permissions will be managed on the front and back end. We will again pass the permissions to Vue using the shared data Middleware.


Laravel Inertia Middleware

So, in the HandleInertiaRequests Middleware, you pass the permissions. Those permissions can come from some package or your own custom implementation. For example, let's add two permissions.

app/Http/Middleware/HandleInertiaRequests.php:

class HandleInertiaRequests extends Middleware
{
// ...
 
public function share(Request $request): array
{
return array_merge(parent::share($request), [
'flash' => [
'message' => fn () => $request->session()->get('message')
],
'user' => [
'name' => $request->user()?->name,
'email' => $request->user()?->email,
],
'permissions' => [
'posts_view' => true,
'posts_manage' => true,
],
]);
}
}

Vue Component Props

Next, we can add permissions as props so that we would...

The full lesson is only for Premium Members.
Want to access all 18 lessons of this course? (56 min read)

You also get:

  • 75 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord