Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaraBABA's avatar

Passing laravel roles to vue

Hello,

i am using the Spatie roles.

Let's say I have a full component in vue which resides inside a laravel blade view file. How can I check the user role (Auth::user()->HasRole('admin')) within the Vue component(and not blade)?

Thank you.

0 likes
4 replies
wingly's avatar

There are multiple ways but if you only need this here you can pass it as a prop

<your-component :is-admin="{{ json_encode(Auth::user()->hasRole('admin')) }}"></your-component>

And then in your component

<template>

</template>

<script>
export default {
	props: ['isAdmin']
}
</script>
LaraBABA's avatar

Tiny modification, if should be this:

    <market-component :is-admin="{{json_encode(Auth::user()->hasRole('admin'))}}"></market-component>

If you change your code to mine I will accept yours as the accepted answer.

Please or to participate in this conversation.