Authorize a controller action before the Vue page

authorize() in the controller is the check. The Vue button can hide itself later.

For your AI agent

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

Read https://laravel-vuejs.space/laravel-authorize-controller-vue.md
authorize() in the controller is the check. The Vue button can hide itself later.
Do not pass $request->user()->isadmin from Vue as a field named authorized.
Do not skip authorize on update because edit already checked.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Laravel authorize Vue” check the user in the component and leave the controller open. Call authorize before the write and before you render an editor. The policy guide is the policy class. This page is the call.

TL;DR

  • authorize() in the controller is the check.
  • The Vue button can hide itself later.
  • Do not pass $request->user()->is_admin from Vue as a field named authorized.
  • Do not skip authorize on update because edit already checked.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

php
public function edit(Post $post): Response
{
    $this->authorize('update', $post);

    return Inertia::render('posts/Edit', [
        'post' => $post->only(['id', 'title']),
    ]);
}

A guest or the wrong user gets a 403. Inertia shows its error page. The Edit vue file does not mount, so it does not need a branch for “not allowed” in order to be safe.

The matching policy method is update(User $user, Post $post): bool. Return false, do not abort inside the policy.

What to avoid#

Gotcha

Do not pass $request->user()->is_admin from Vue as a field named authorized. The controller would be trusting the browser. Do not skip authorize on update because edit already checked. They are different requests.

FAQ#

How do I authorize a controller action before the Vue page?

authorize() in the controller is the check. The Vue button can hide itself later.

What goes wrong with Laravel authorize Vue?

Many developers check the user in the component and leave the controller open. Do not pass $request->user()->is_admin from Vue as a field named authorized.

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.