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/ */
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();
}