geowrgetudor/laravel-spatie-permissions-vue
最新稳定版本:1.0.0
Composer 安装命令:
composer require geowrgetudor/laravel-spatie-permissions-vue
包简介
Use Laravel Spatie Permission package in Vue
README 文档
README
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).
统计信息
- 总下载量: 12.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-13