farbesofts / checkrolepast
A API Library for Laravel
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: 2025-04-20 05:47:39 UTC
README
checkRole is a simple and lightweight library that provides developers with a useful tool when creating login restrictions in personalized schedules by users to a specific role in the system.
- Every user has a single schedule defined.
Documentation
(Comming Soon)
Quick Installation
Begin by installing the package through Composer. The best way to do this is through your terminal via Composer itself:
composer require farbesofts/checkrolepast
Configuration
To publish the config file and NotAccess view, run the following:
php artisan vendor:publish
Choose the option where the library is located, in my case:
[2] Provider: Farbesofts\Checkrolepast\CheckrolepastServiceProvider
Service Provider
- copy the following in config.app (array Providers)
Farbesofts\Checkrolepast\CheckrolepastServiceProvider::class,
Middleware kernel.php
- copy on App\Http\Kernel.php -> (array $routeMiddleware):
'CheckRolePast' => \Farbesofts\Checkrolepast\Middleware\CheckRolePast::class,
Migrations
- Migrate the models
php artisan make:auth
php artisan migrate
If you are using a library of roles and permissions, before to migrate on config/checkrolepast.php to change 'run-migrations' => false, and only you migrate:
2019_03_16_160254_create_timetables_table
Header on User Model
- Copy on App\User.php Model:
use Farbesofts\Checkrolepast\Models\Role; use Farbesofts\Checkrolepast\Models\Timetable; use Illuminate\Support\Facades\Auth;
Methods on User Model
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(); }
Routing with CheckRolePast Middleware
- Copy on routes\web.php: example (Role:admin)
Route::get('/notaccess', function () { return view('notaccess'); }); Route::group(['middleware' => 'CheckRolePast:admin'], function() { Route::get('/home', 'HomeController@index')->name('home'); });