After installed you can do like this in Vuejs:
<div v-if="can('edit post')">
<!-- Edit post form -->
</div>
<div v-if="is('super-admin')">
<!-- Show admin tools -->
</div>
<!-- you can use OR operator -->
<div v-if="can('edit post | delete post | publish post')">
<!-- Do something -->
</div>
<div v-if="is('editor | tester | user')">
<!-- Do something -->
</div>
<!-- you can use AND operator -->
<div v-if="can('edit post & delete post & publish post')">
<!-- Do something -->
</div>
<div v-if="is('editor & tester & user')">
<!-- Do something -->
</div>
This package require to use laravel-permission
composer require ahmedsaoud31/laravel-permission-to-vuejs=dev-master
npm i laravel-permission-to-vuejs
First, add the LaravelAndVueJS\Traits\LaravelPermissionToVueJS
trait to your User
model(s):
use LaravelAndVueJS\Traits\LaravelPermissionToVueJS;
class User extends Authenticatable
{
use LaravelPermissionToVueJS;
// ...
}
Second, add the laravel-permission-to-vuejs
plugin in app.js
file:
import LaravelPermissionToVueJS from 'laravel-permission-to-vuejs';
Vue.use(LaravelPermissionToVueJS);
Third, pass permissions from Laravel To Vuejs, in HTML header add this code:
<script type="text/javascript">
window.Laravel = {
csrfToken: "{{ csrf_token() }}",
jsPermissions: {!! auth()->check()?auth()->user()->jsPermissions():null !!}
}
</script>
The MIT License (MIT).