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.
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>
Brilliant!! Thank you so much!
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.
@boubou sorry typed it too fast answer updated
Please sign in or create an account to participate in this conversation.