定制 mashyindustries/laraccess 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mashyindustries/laraccess

Composer 安装命令:

composer require mashyindustries/laraccess

包简介

Roles, Inheritence & Permissions for Laravel 5.4

README 文档

README

Works with Laravel 5.4

This package allows to save roles in a database. Roles can inherit other roles too.

It includes blade directives & middleware

Install

You can install the package via composer:

$ composer require mashyindustries/laraccess

This service provider must be installed.

// config/app.php
'providers' => [
    ...
    Mashy\Laraccess\LaraccessServiceProvider::class,
];

You can publish the migration with:

php artisan vendor:publish --provider="Mashy\Laraccess\LaraccessServiceProvider" --tag="migrations"

The package assumes that your users table name is called "users". If this is not the case you should manually edit the published migration to use your custom table name.

After the migration has been published you can create the role tables with:

php artisan migrate

You can publish the config-file with:

php artisan vendor:publish --provider="Mashy\Laraccess\LaraccessServiceProvider" --tag="config"

Usage

First add the Mashy\Laraccess\Traits\HasRoles trait to your User model.

use Mashy\Laraccess\Traits\HasRoles;

class User
{
    use HasRoles;
    
    // ...
}

This package allows for users to be associated with roles.

You can create roles with:

use Mashy\Laraccess\Models\Role;

$role = Role::create([
    'name' => 'Writer', //optional
    'slug' => 'writer', //required
    'description' => '' //optional
]);

The HasRoles adds collections to your models.

$roles = $user->roles(); // returns a collection

Using Roles

A role can be assigned to a user:

$user->assignRole('writer');

// you can also assign multiple roles at once
$user->assignRole('writer', 'admin');
$user->assignRole(['writer', 'admin']);

A role can be removed from a user:

$user->removeRole('writer');

Roles can also be synced :

//all current roles will be removed from the user and replace by the array given
$user->syncRoles(['writer', 'admin']);

You can determine if a user has a certain role:

$user->hasRole('writer');

You can also determine if a user has any of a given list of roles:

$user->hasAnyRole(['writer', 'admin']);

You can also determine if a user has all of a given list of roles:

$user->hasAllRoles(['writer', 'admin']);

Using blade directives

This package also adds Blade directives to verify whether the currently logged in user has all or any of a given list of roles.

@role('writer')
I'm a writer!
@else
I'm not a writer...
@endrole
@hasanyrole(['writer', 'admin'])
I have one or more of these roles!
@else
I have none of these roles...
@endrole
@hasallroles(['writer', 'admin'])
I have all of these roles!
@else
I don't have all of these roles...
@endrole

You can use Laravel's native @can directive to check if a user has a certain permission.

Using a middleware

Information coming soon...

Inheritance

Information coming soon...

Credits

This package was based on Spatie/Laravel-Permission

Alternatives

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固