8000 GitHub - geowrgetudor/laravel-spatie-permissions-vue: Spatie Laravel Permission to Vue
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

geowrgetudor/laravel-spatie-permissions-vue

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Use Laravel Spatie Permission in Vue3

This package is fork of the original package (ahmedsaoud31/laravel-permission-to-vuejs) and requires laravel-permission by Spatie.

It supports SSR.

Installation

composer require geowrgetudor/laravel-spatie-permissions-vue

Setup

Add the trait to your User model:

use SpatiePermissionVue\Traits\RolesPermissionsToVue;

class User extends Authenticatable
{
    // ...
    use RolesPermissionsToVue;
}

Import and use laravel-spatie-permissions-vue plugin into your app.js file:

import RolesPermissionsToVue from "../../vendor/geowrgetudor/laravel-spatie-permissions-vue/src/js";

// ...

app.use(RolesPermissionsToVue);

Pass the Spatie roles & permissions to a global var called vueSpatiePermissions in your app.blade.php or whatever your main blade template is called:

<script type="text/javascript">
  window.vueSpatiePermissions = {!! auth()->check() ? auth()->user()->getRolesPermissionsAsJson() : 0 !!}
</script>

Usage

You can make use of can and is global functions to check for permissions and roles of the current user.

<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>

License

The MIT License (MIT).

About

Spatie Laravel Permission to Vue

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 84.5%
  • PHP 15.5%
0