Put a permission on the route

role and permission middleware refuse the request. The Vue page only receives a boolean it can show.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/spatie-permission-middleware-vue.md
role and permission middleware refuse the request. The Vue page only receives a boolean it can show.
Do not spell the permission differently in the seeder and the route.
Do not grant it from the Vue page.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Spatie permission middleware Vue” check v-if="can('posts.update')" in the page and never register the middleware. The permissions guide installs the package and shares a boolean. This page is the route.

TL;DR

  • role and permission middleware refuse the request.
  • The Vue page only receives a boolean it can show.
  • Do not spell the permission differently in the seeder and the route.
  • Do not grant it from the Vue page.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

Publish and migrate are in that guide. The alias belongs in bootstrap/app.php if it is not registered yet:

php
$middleware->alias([
    'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
    'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
]);
php
Route::post('/posts', [PostController::class, 'store'])
    ->middleware(['auth', 'permission:posts.update']);

A user without posts.update gets a 403 before the controller. The Vue page can still hide the button from the boolean the permissions guide shares. Hiding is not this middleware.

What to avoid#

Gotcha

Do not spell the permission differently in the seeder and the route. posts.update and post.update are two permissions. Do not grant it from the Vue page.

FAQ#

How do I put a permission on the route?

role and permission middleware refuse the request. The Vue page only receives a boolean it can show.

What goes wrong with Spatie permission middleware Vue?

Many developers check `v-if="can('posts. Do not spell the permission differently in the seeder and the route.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.