PHP code example of saeidsharafi / laravel-permission-generator

1. Go to this page and download the library: Download saeidsharafi/laravel-permission-generator 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/ */

    

saeidsharafi / laravel-permission-generator example snippets


    use App\Enums\PermissionEnum; // Adjust namespace if you changed the output path
    
    // Example Policy
    public function updateAny(User $user): bool
    {
        return $user->hasPermissionTo(PermissionEnum::POST_UPDATE_ANY->value);
    }
    
    // Example Middleware or Controller Check
    if (! Auth::user()?->can(PermissionEnum::ACCESS_ADMIN_DASHBOARD->value)) {
        abort(403);
    }
    
bash
    php artisan vendor:publish --provider="SaeidSharafi\LaravelPermissionGenerator\PermissionGeneratorServiceProvider" --tag="permission-generator-config"
    
bash
    php artisan vendor:publish --provider="SaeidSharafi\LaravelPermissionGenerator\PermissionGeneratorServiceProvider" --tag="permission-generator-stubs"
    
bash
    php artisan permissions:generate-enum
    
bash
    php artisan permissions:sync