odhiamboatieno/laravel-entrust 问题修复 & 功能扩展

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

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

odhiamboatieno/laravel-entrust

Composer 安装命令:

composer require odhiamboatieno/laravel-entrust

包简介

This package provides a flexible solution to add ACL to Laravel

README 文档

README

A robust and flexible package to manage role-based permissions for your Laravel applications.

Version Compatibility

Laravel Laravel Entrust
12.x [4.x]
11.x [4.x]
10.x [4.x]
9.x [3.x]
8.x [2.x]
7.x - 5.x [1.x]

📌 Table of Contents

🚀 Introduction

Laravel Entrust is a role and permission management package for Laravel applications, providing an intuitive way to manage user roles and permissions.

Key Features

  • Role and Permission Management
  • Middleware for Authorization Control
  • Configurable Permission Structure
  • Easy-to-use API for Role and Permission Checks

✅ Installation

  1. Install the package via composer:
composer require odhiamboatieno/laravel-entrust
  1. Publish the package configuration:
php artisan vendor:publish --tag="LaravelEntrust"
  1. Run the setup command to create migration files:
php artisan laravel-entrust:setup
  1. Add the LaravelEntrustUserTrait to your User model:
use Odhiambo\LaravelEntrust\Traits\LaravelEntrustUserTrait;

class User extends Model
{
    use LaravelEntrustUserTrait;
}

⚙️ Configuration

  1. Configure the published file in config/entrust.php to set your models, tables, and guard settings.

  2. Define the roles, permissions, and relationships as needed for your application.

✅ Usage

Roles and Permissions

Assign roles and permissions to users using the trait methods:

$user = User::find(1);
$user->attachRole('admin');
$user->hasRole('admin'); // true
$user->hasPermission('create-post');

Middleware

Protect your routes using middleware for roles or permissions:

Route::group(['middleware' => ['role:admin']], function() {
    Route::get('/dashboard', [DashboardController::class, 'index']);
});

Route::get('/posts', [PostController::class, 'index'])->middleware('permission:view-posts');

Soft Deletes

If using soft deletes on roles or permissions, ensure to clear relationships before force deleting:

$role = Role::find(1);
$role->users()->sync([]);
$role->permissions()->sync([]);
$role->forceDelete();

❓ Troubleshooting

If you encounter migration errors, ensure your database uses the correct integer type (BigInteger) for foreign keys.

💡 Contribution Guidelines

  • Follow PSR-12 coding standards.
  • Submit bug reports or feature requests via GitHub Issues.
  • Pull requests are welcome.

📜 License

Laravel-Entrust is licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-10