Laravel-permission: Use blade directive into vue

Created on 3 Nov 2017  路  1Comment  路  Source: spatie/laravel-permission

@role('writer')
I am a writer!
@else
I am not a writer...
@endrole

How can I use the above functionality in my vue file.

>All comments

You can auth()->user()->getRoleNames() to get a collection of role names that can be passed into your Vue component.

For example in your blade view:

<vue-component :user-roles="{{ json_encode(auth()->user()->getRoleNames()) }}"></vue-component>

In your component you can then simple check if a certain role is in that array with

<div v-if="userRoles.includes('writer')">
    I'm a writer.
</div>
<div v-else>
    Not a writer.
</div>

Hopefully this is what you're looking for?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ionesculiviucristian picture ionesculiviucristian  路  4Comments

hosseinnedaei picture hosseinnedaei  路  3Comments

holymp2006 picture holymp2006  路  4Comments

ghost picture ghost  路  3Comments

NattananWs picture NattananWs  路  3Comments