Hide a Vue button with a gate

Share the gate as a boolean. The controller still calls authorize on the POST.

For your AI agent

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

Read https://laravel-vuejs.space/laravel-gate-button-vue.md
Share the gate as a boolean. The controller still calls authorize on the POST.
Do not send the whole gate map, or the user model, so the page can call can itself.
Do not hide the button with CSS.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Laravel gate Vue button” hide the button and stop. The POST still runs. Share a boolean for the button, and keep authorize on the write. The policy guide defines update.

TL;DR

  • Share the gate as a boolean.
  • The controller still calls authorize on the POST.
  • Do not send the whole gate map, or the user model, so the page can call can itself.
  • Do not hide the button with CSS.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

php
return Inertia::render('posts/Show', [
    'post' => $post->only(['id', 'title']),
    'canUpdate' => $request->user()?->can('update', $post),
]);
vue
<button v-if="canUpdate" type="button" @click="edit">Edit</button>

can runs the same policy the controller will run. The boolean is a copy from the last response. It goes stale if a teammate changes the owner’s id. The next POST still checks.

What to avoid#

Gotcha

Do not send the whole gate map, or the user model, so the page can call can itself. Vue cannot see the policy. Do not hide the button with CSS. v-if removes it. A person can still POST, which is why the controller check stays.

FAQ#

How do I hide a Vue button with a gate?

Share the gate as a boolean. The controller still calls authorize on the POST.

What goes wrong with Laravel gate Vue button?

Many developers hide the button and stop. Do not send the whole gate map, or the user model, so the page can call can itself.

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.