承接 nietthijmen/laravel-roles 相关项目开发

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

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

nietthijmen/laravel-roles

最新稳定版本:1.0.0

Composer 安装命令:

composer require nietthijmen/laravel-roles

包简介

This is my package laravel-roles

README 文档

README

This package provides a simple and easy way to manage roles in your laravel package.

Installation

  1. Install the package via composer:
composer require nietthijmen/laravel-roles
  1. Run the install command to publish the configuration file:
php artisan roles:install
  1. Grab a cup of coffee and wait for the package to be installed.
  2. Add the HasRoles trait to your User model:
use Nietthijmen\LaravelRoles\Traits\HasRoles;
class User extends Authenticatable
{
    use HasRoles;

    // ...
}
  1. Alias your middleware (if you want to use this)
// bootstrap/app.php
withMiddleware(function (Middleware $middleware) {
        $middleware->alias([
            'role' => \NietThijmen\LaravelRoles\Http\Middleware\RoleMiddleware::class
        ]);
})
  1. Add the RoleServiceProvider
// bootstrap/providers.php
<?php

return [
    //...
    \NietThijmen\LaravelRoles\Providers\RoleServiceProvider::class
];
 
  1. You're good to go 🎉

Usage

Blade directive

@role('admin')
    <p>You are an admin!</p>
@endrole

Middleware

You can use the middleware to protect your routes:

Route::middleware(['role:admin'])->group(function () {
    Route::get('/admin', function () {
        return 'You are an admin!';
    });
});

Manual usage

auth()->user()->hasRole('admin'); // returns true if the user has the admin role

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-13