定制 nijwel/user-roles 二次开发

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

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

nijwel/user-roles

Composer 安装命令:

composer require nijwel/user-roles

包简介

A user role management package for Laravel

README 文档

README

nijwel/user-roles is a Laravel package for managing user roles and permissions with ease. It provides a simple interface to manage user roles and permissions, integrating seamlessly with Laravel's authentication system.

You can visit github repository - https://github.com/nijwel/user_roles.git

Features

  • Role Management: Create, update, and delete user roles.
  • Permission Management: Assign and manage permissions for roles.
  • Integration with Laravel Auth: Works with Laravel's built-in authentication system.
  • Flexible Configuration: Customize role and permission settings.

Installation

Via Composer

Install the package via Composer:

composer require nijwel/user-roles

Migration

php artisan migrate

Publish Configuration (If Applicable)

If the package includes configuration files, publish them using:

php artisan vendor:publish --provider="Nijwel\UserRoles\UserRoleServiceProvider"

Note: If you receive the message "No publishable resources for tag []", it indicates there are no additional configuration files to publish. Please refer to the package documentation for further instructions.

Configuration

Add the service provider to the providers array in your config/app.php file:

'providers' => [
    // Other service providers...
    Nijwel\UserRoles\UserRolesServiceProvider::class,
],

Usage

Creating Roles You can create roles using the Role model provided by the package:

Now you can insert the side-ber menu name or top-bar menu name into permissions table

Example : student , subcategories , products , accounts etc

Role name is input and permissions is checkbox array. you can handle from same form and post request

#Your Controller

use Nijwel\UserRoles\Services\UserRoleService;

protected $UserRoleService;

public function __construct(UserRoleService $UserRoleService)
{
    $this->UserRoleService = $UserRoleService;
}

#Get all role

UserRoleService::getAllRole();

#Get singe role

UserRoleService::getRole($id);

#Store role

UserRoleService::createRole($request->all());

#Update role

UserRoleService::updateRole($request->all(), $id);

#delete role

UserRoleService::destroyRole($id);

Get all permission list.

NB: permission means your side bar name

UserRoleService::getAllPermission();

#Get single permission

UserRoleService::getPermission($id);

#Store permissions

UserRoleService::createPermission($request->all());

#Update permissions

UserRoleService::updatePermission($request->all(), $id);

#delete permissions

UserRoleService::destroyPermission($id);

#Get All role with permission

NB: You can handle with one form

UserRoleService::getAllRoleWithPermission();

#Get single role with permission

UserRoleService::getRoleWithPermission($id);

#Store role with permission [ This is the array data for role and permission ]

//Permissions is array value ;
UserRoleService::createRoleWithPermission($request->all());

#Update role with permission [Array]

//Permissions is array value ;
UserRoleService::updateRoleWithPermission($request->all(), $id);

#delete role with permission

UserRoleService::destroyRoleWithPermission($id);

For blade file

@if (isPermission('Employee'))
    <li class="nav-item text-danger">
        <a class="nav-link"
            href="{{ route('index.employee') }}">Employee</a>
    </li>
@endif
@if (isPermission('Manager'))
    <li class="nav-item text-danger">
        <a class="nav-link" href="{{ route('index.manager') }}">Manager</a>
    </li>
@endif

Use the Middleware in a Laravel Application

Once the package is installed in a Laravel application, you can use the middleware in routes or controllers.

Using Middleware in Routes:

You can apply the middleware to routes like this:

// routes/web.php

Route::get('/admin', function () {
    // Only users with the 'admin' role can access this route
})->middleware('permission:your-permission');

Using Middleware in Controllers:

You can also apply the middleware in a controller:

// app/Http/Controllers/AdminController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AdminController extends Controller
{
    public function __construct()
    {
        $this->middleware('permission:your-permission');
    }

    public function index()
    {
        // Your logic here
    }
}

nijwel/user-roles 适用场景与选型建议

nijwel/user-roles 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 nijwel/user-roles 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nijwel/user-roles 我们能提供哪些服务?
定制开发 / 二次开发

基于 nijwel/user-roles 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-02