Essentials
Perimeters
Structure your applications access scopes.
Perimeter
Create your perimeter using the command:
php artisan make:perimeter GlobalPerimeter
use Lomkit\Access\Perimeters\Perimeter;
class GlobalPerimeter extends Perimeter
{
//
}
You don't need to define much more in the perimeter, this is more functional related.
Overlay Perimeter
In some cases, you may want to give the ability for a perimeter to overlay with others. This will make the perimeter non-final in use.
php artisan make:perimeter SharedPerimeter --overlay
use Lomkit\Access\Perimeters\OverlayPerimeter;
class SharedPerimeter extends OverlayPerimeter
{
//
}
Here, for example, we may want a SharedPerimeter to apply first to check if the post has been shared with the current user.
This allows it to surpass other perimeters while still working in coordination with them.
use Illuminate\Database\Eloquent\Builder;
class TaskControl extends Control
{
protected function perimeters(): array
{
return [
SharedPerimeter::new()
->allowed(function (Model $user, string $method) {
return true;
})
->should(function (Model $user, Model $model) {
return $model->isSharedWith($user);
})
->query(function (Builder $query, Model $user) {
return $query->whereHas('task_shared_with_users', function(Builder $query){
$query->where('id', $user->id);
});
}),
GlobalPerimeter::new()
// ...
];
}
}