承接 orderonlineid/role-permission-laravel-mongodb 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

orderonlineid/role-permission-laravel-mongodb

最新稳定版本:1.0.10

Composer 安装命令:

composer require orderonlineid/role-permission-laravel-mongodb

包简介

Permission handling for Laravel Mongodb

README 文档

README

This package provides role and permission management for Laravel applications using MongoDB as the database.

Installation

To install this package, run the following Composer command:

composer require orderonlineid/role-permission-laravel-mongodb

After the installation is complete, you need to publish the configuration file and migrations by running the following command:

php artisan vendor:publish --provider="OrderOnlineId\RolePermissionMongoDb\RolePermissionMongoDbServiceProvider"

Usage

Setting Up Roles and Permissions To set up roles and permissions, you can use the Role and Permission models provided by this package.

use OrderOnlineId\RolePermissionMongoDb\Models\Role;
use OrderOnlineId\RolePermissionMongoDb\Models\Permission;

// Create a new role
$role = Role::create(['name' => 'admin']);

// Create a new permission
$permission = Permission::create(['code' => 'create','name' => 'Create']);

// Assign the permission to the role
$role->givePermissionTo($permission);

Assigning Roles and Permissions to Users

To assign roles and permissions to users, you can use the HasRoles and HasPermissions traits provided by this package.

use App\Models\User;
use OrderOnlineId\RolePermissionMongoDb\Traits\HasRoles;
use OrderOnlineId\RolePermissionMongoDb\Traits\HasPermissions;

class User extends Authenticatable
{
    use HasRoles, HasPermissions;

    // ...
}

After that, you can assign roles and permissions to users like this:

$user = User::find(1);

$permission = Permission::create(['code' => 'create','name' => 'Create']);

// Assign a role
$user->assignRole($permission);

// Grant a permission
$user->givePermissionTo('view', 'users');

Checking User Roles and Permissions

You can check if a user has a specific role or permission like this:

$user = User::find(1);

// Check for a role
if ($user->hasRole('admin')) {
    // ...
}

// Check for a permission
if ($user->hasAllPermission('view', 'users')) {
    // ...
}

For more information on using this package, please refer to the documentation or the configuration file.

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-19