PHP code example of farbesofts / checkrole

1. Go to this page and download the library: Download farbesofts/checkrole library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

farbesofts / checkrole example snippets


Farbesofts\Checkrole\CheckroleServiceProvider::class,

'CheckRole' => \Farbesofts\Checkrole\CheckroleServiceProvider::class,

use Farbesofts\Checkrole\Models\Role;
use Farbesofts\Checkrole\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' => 'CheckRole:admin'], function() {
    Route::get('/home', 'HomeController@index')->name('home');
});

php artisan vendor:publish

php artisan make:auth
php artisan migrate