PHP code example of fireworkweb / laravel-gates

1. Go to this page and download the library: Download fireworkweb/laravel-gates library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fireworkweb / laravel-gates example snippets


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

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



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;
    }
}