定制 appzcoder/laravel-roles 二次开发

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

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

appzcoder/laravel-roles

Composer 安装命令:

composer require appzcoder/laravel-roles

包简介

Laravel 5 User Role Manager

README 文档

README

Laravel 5 User Role Manager

The idea of this package came from laracast laracasts/Users-and-Roles-in-Laravel and now it is built for laravel 5.

Requirements

Laravel >=5.1
PHP >= 5.5.9 

Installation

  1. Run

    composer require "appzcoder/laravel-roles":"dev-master"
    
  2. Add service provider into /config/app.php file.

    'providers' => [
        ...
    
        Appzcoder\LaravelRoles\LaravelRolesServiceProvider::class,
    ],
  3. Publish migrations

    php artisan vendor:publish
    
  4. Run migrate command

    php artisan migrate
    
  5. Include UserRoles trait to your user model located at /app/User.php

    use Appzcoder\LaravelRoles\Traits\UserRoles;
    
    class User extends Model implements AuthenticatableContract, CanResetPasswordContract
    {
        use Authenticatable, CanResetPassword, UserRoles;

Usage

Use the routes as bellow.

Route::get('/roles', function () {

    /* Create user if needed
    App\User::create([
    'name' => 'Sohel Amin',
    'email' => 'sohelamincse@gmail.com',
    'password' => bcrypt('123456'),
    ]);
     */

    $user = App\User::first();

    /* Create roles
    $role = new Appzcoder\LaravelRoles\Models\Role;
    $role->name = 'admin';
    $role->save();
     */

    /* Assign and remove role from user
    $role = Appzcoder\LaravelRoles\Models\Role::whereName('admin')->first();
    $user->assignRole($role);
    //$user->removeRole(2);
     */

    return $user->roles;
});

Route::get('/admin', ['middleware' => 'role:admin', 'uses' => 'AdminController@index']);

##Author

Sohel Amin

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-06