Downloads
Stars
Version
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.
(Comming Soon)
Begin by installing the package through Composer. The best way to do this is through your terminal via Composer itself:
composer require farbesofts/checkrolepast
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
Farbesofts\Checkrolepast\CheckrolepastServiceProvider::class,
'CheckRolePast' => \Farbesofts\Checkrolepast\Middleware\CheckRolePast::class,
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
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();
}
Route::get('/notaccess', function () {
return view('notaccess');
});
Route::group(['middleware' => 'CheckRolePast:admin'], function() {
Route::get('/home', 'HomeController@index')->name('home');
});