farbesofts / checkrolepast
用于Laravel的API库
1.0
2019-03-19 15:31 UTC
Requires
- php: >=5.6.4
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is auto-updated.
Last update: 2024-09-20 04:39:05 UTC
README
checkRole是一个简单且轻量级的库,为开发者提供了一个在创建用户对系统特定角色的个性化时间表登录限制时的有用工具。
- 每个用户都有一个单独的时间表。
文档
(即将推出)
快速安装
首先,通过Composer安装该包。最好的方法是通过终端执行Composer本身
composer require farbesofts/checkrolepast
配置
要发布配置文件和NotAccess视图,运行以下命令
php artisan vendor:publish
选择库所在的选项,以我的情况为例
[2] Provider: Farbesofts\Checkrolepast\CheckrolepastServiceProvider
服务提供者
- 在config.app(数组 Providers)中复制以下内容
Farbesofts\Checkrolepast\CheckrolepastServiceProvider::class,
中间件kernel.php
- 在App\Http\Kernel.php -> (数组 $routeMiddleware)中复制
'CheckRolePast' => \Farbesofts\Checkrolepast\Middleware\CheckRolePast::class,
迁移
- 迁移模型
php artisan make:auth
php artisan migrate
如果您正在使用角色和权限库,在迁移到config/checkrolepast.php之前,将'run-migrations' => false更改为,并且只进行迁移
2019_03_16_160254_create_timetables_table
用户模型上的头信息
- 在App\User.php模型中复制
use Farbesofts\Checkrolepast\Models\Role; use Farbesofts\Checkrolepast\Models\Timetable; use Illuminate\Support\Facades\Auth;
用户模型上的方法
public function roles() { return $this->belongsToMany(Role::class)->withTimestamps(); } public function hasRole($role) { if ($this->roles()->where('name', $role)->first()) { return true; } return false; } public function Timetable(){ return $this->hasOne(Timetable::class); } public function getTimetable(){ return $this->Timetable()->where('user_id',Auth::user()->id)->first(); }
使用CheckRolePast中间件的路由
- 在routes\web.php: example (角色:admin)中复制
Route::get('/notaccess', function () { return view('notaccess'); }); Route::group(['middleware' => 'CheckRolePast:admin'], function() { Route::get('/home', 'HomeController@index')->name('home'); });