New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

fireworkweb/laravel-gates

Permission handling for Laravel using Gates with Route Names
35,417 5
Install
composer require fireworkweb/laravel-gates
Latest Version:v0.12
PHP:^7.3|^8.0
Laravel:9 – 12
Older releases:5 – 8
License:MIT
Last Updated:Nov 24, 2025
Links: GitHub  ·  Packagist
Maintainer: dbpolito

fireworkweb/laravel-gates

Packagist Version GitHub Workflow Status Codecov Scrutinizer code quality (GitHub/Bitbucket) Packagist Downloads

This package allows you to manage permissions using Gates with Route Names.

Installation

You can install the package via composer:

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.

protected $routeMiddleware = [
    // ...
    'gate' => \Fireworkweb\Gates\Middlewares\Gate::class,
    'gate_optional' => \Fireworkweb\Gates\Middlewares\GateOptional::class,
];

Usage

Here is an example:

Route::middleware('gate')->group(function () {
    // ...
    Route::get('posts/{post}/edit')->name('posts.edit');
});
<?php

namespace App\Policies;

use App\Post;
use App\User;
use Fireworkweb\Gates\Traits\HasGates;

class PolicyWithResourceGates
{
    use HasGates;

    protected static function gateRouteName() : string
    {
        return 'posts';
    }

    protected static function gateAbilities() : array
    {
        return [
            'edit' => '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:

# 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

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email contact@fireworkweb.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

spiti/laravel-permission-6

Permission handling for Laravel 8.0 and up

1,252 0
spatie/laravel-permission

Permission handling for Laravel 12 and up

128,021,037 12,976
offspring/laravel-permission

Permission handling for Laravel 5.4 to 5.8

13,848 0
beam-australia/laravel-permission

Permission handling for Laravel 6.0 and up

11,740 0
larakeeps/guard-shield

GuardShield é um repositório laravel com a função de aplicar regras de permissio...

1,820 1

Version History

Version Released PHP Laravel License
v0.12 ^7.3|^8.0 ^9.0|^10.0|^11.0|^12.0 MIT
v0.11 ^7.3|^8.0 ^9.0|^10.0|^11.0 MIT
v0.10 ^7.3|^8.0 ^9.0|^10.0 MIT
v0.9 ^7.3|^8.0 ^5.8|^6.0|^7.0|^8.0|^9.0 MIT
v0.8 ^7.3|^8.0 ^5.8|^6.0|^7.0|^8.0|^9.0 MIT