Download the PHP package soyhuce/laravel-fluent-policy without Composer
On this page you can find all versions of the php package soyhuce/laravel-fluent-policy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download soyhuce/laravel-fluent-policy
More information about soyhuce/laravel-fluent-policy
Files in soyhuce/laravel-fluent-policy
Package laravel-fluent-policy
Short Description Write fluent policies in Laravel
License MIT
Homepage https://github.com/soyhuce/laravel-fluent-policy
Informations about the package laravel-fluent-policy
Write fluent policies in Laravel
Write your policies fluently in Laravel.
Installation
You can install the package via composer:
Usage
The goal of this package is to write your policies more easily in a clean syntax.
For exemple, the following policy:
can be re-written as:
You can customise the response if needed :
You can also call another policy or gate this way :
Custom Http status
You can deny the policy returning a custom http status code :
In the case of 404
status code, you can use the shortcut
Lazy evaluation
The different branches allowWhen
and denyWhen
are evaluated lazily which mean that the following code is completely
correct :
2
will only be called if previous branches are all false. We are sure that here $post->published_at
is not null
thanks to 1
.
PHPStan
When running PHPStan on
an error is raised on 2
(Cannot call method
isFutureon Carbon|null
).
An extension is available to fix this issue and should be included in your phpstan.neon
file.
Unfortunately, due to a PHPStan limitation, you still have to rewrite your policy a little bit :
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Bastien Philippe
- All Contributors
License
The MIT License (MIT). Please see License File for more information.