geowrgetudor/laravel-spatie-permissions-vue 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 24
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-13