https://github.com/fireworkweb/laravel-gates
Permission handling for Laravel using Gates with Route Names
https://github.com/fireworkweb/laravel-gates
Last synced: 10 months ago
JSON representation
Permission handling for Laravel using Gates with Route Names
- Host: GitHub
- URL: https://github.com/fireworkweb/laravel-gates
- Owner: fireworkweb
- License: mit
- Created: 2020-03-19T22:16:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-30T19:22:23.000Z (over 1 year ago)
- Last Synced: 2025-08-24T12:14:25.889Z (10 months ago)
- Language: PHP
- Size: 34.2 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# fireworkweb/laravel-gates
[](https://packagist.org/packages/fireworkweb/laravel-gates)
[](https://github.com/fireworkweb/laravel-gates/actions?query=workflow%3Arun-tests)
[](https://codecov.io/gh/fireworkweb/laravel-gates)
[](https://scrutinizer-ci.com/g/fireworkweb/laravel-gates)
[](https://packagist.org/packages/fireworkweb/laravel-gates)
This package allows you to manage permissions using Gates with Route Names.
## Installation
You can install the package via composer:
```bash
composer require fireworkweb/laravel-gates
```
### Package Middlewares
This package comes 2 middlewares:
* `Gate` - Checks current route gates, if no matching gate, breaks
* `GateOptional` - Checks current route gates, if no matching gate, logs
You can add them inside your `app/Http/Kernel.php` file.
```php
protected $routeMiddleware = [
// ...
'gate' => \Fireworkweb\Gates\Middlewares\Gate::class,
'gate_optional' => \Fireworkweb\Gates\Middlewares\GateOptional::class,
];
```
## Usage
Here is an example:
```php
Route::middleware('gate')->group(function () {
// ...
Route::get('posts/{post}/edit')->name('posts.edit');
});
```
```php
'edit',
];
}
public function edit(User $user, Post $post)
{
return $user->id === $post->user_id;
}
}
```
That will register a gate `posts.edit` and on route `posts/1/edit` it will check if you on `App\Policies\Post@edit` injecting route parameters.
### Commands
You have commands to help you find routes without gate:
```bash
# it will get the routes that has `gate` middleware
fwd artisan gates:routes-without-gate
# in case you are using a custom middleware name or want to check the optional one
fwd artisan gates:routes-without-gate gate_optional
```
## Testing
``` bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security
If you discover any security related issues, please email contact@fireworkweb.com instead of using the issue tracker.
## Credits
- [Daniel Polito](https://github.com/dbpolito)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.