for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Traits;
use App\Models\User;
use App\Models\UserRolePermissions;
use Illuminate\Support\Facades\Log;
/**
* AllowTrait only has one function to check permission for the policies
*/
trait AllowTrait
{
protected function checkPermission(User $user, $description)
$allowed = UserRolePermissions::whereRoleId($user->role_id)->whereHas('UserRolePermissionTypes', function($q) use ($description)
$q->where('description', $description);
})->first();
Log::channel('auth')->debug('User '.$user->username.' is trying to get permission for '.$description.'. Result - '.$allowed);
if($allowed)
return $allowed->allow;
}
return false;