[Vuejs]-Laravel | Show/Hide an element according to Roles within vue

0👍

If you are using laravel/breeze with inertia you can access the current authenticated user data using usePage() or $page

you can use usePage() if you want to use it inside the <script></script> tag

const isAdmin = computed(() => {
    return usePage().props.auth.user.role === 'Admin'
})

then if you want it inside the template tag

<div v-if="($page.props.auth.user.role === 'Admin')"></div>

Leave a comment