You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
1016 B

<?php
namespace App\Utilities\Polices;
use App\Documents\PolicyDocument;
use App\Models\ILaravel;
use Illuminate\Database\Eloquent\Model;
trait PolicyConditions
{
private PolicyDocument|null $policy;
private Model|null $model;
protected function auth(): bool
{
return auth()->check();
}
protected function permission($permission): bool
{
return !$this->auth() ? false : auth()->user()->can(['*', $permission]);
}
protected function model($functionName): bool
{
return empty($this->model) ? false : $this->model->{$functionName}();
}
protected function owner(): bool
{
return !$this->auth() || empty($this->model) ? false : $this->model->user_id == auth()->user()->id;
}
protected function group(): bool
{
return !$this->auth() || empty($this->model) ? false : $this->model->group_id == auth()->user()->group_id;
}
protected function guest(): bool
{
return !$this->auth();
}
}