PHP code example of wovosoft / laravel-permissions

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

    

wovosoft / laravel-permissions example snippets


//other imports goes here
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
    // other codes goes here
}



return [
    "route_name_prefix" => "Wovosoft",
    "route_url_prefix" => "backend",
    "middleware" => ["web", "auth"],
    "users_table" => "users",                //Default Laravel Generated Name
    "roles_table" => config("permission.table_names.roles"),                //comes from spatie config file.
    "permissions_table" => config("permission.table_names.permissions"),    //comes from spatie config file
    "default_permissions" => [
        [
            "name" => "add user",
            "description" => "Can Add User"
        ],
        [
            "name" => "edit user",
            "description" => "Can Edit User"
        ],
        [
            "name" => "delete user",
            "description" => "Can Delete User"
        ]
    ],
    "default_roles" => [
        [
            "name" => "Super Admin",
            "description" => "Super Admin Manages Everything"
        ],
        [
            "name" => "User",
            "description" => "User Role"
        ],
        [
            "name" => "Customer",
            "description" => "Customer Role"
        ]
    ]
];


if(auth()->can('permission')){
  echo "Auth user is allowed to perform this operation";
}

if(App\User::find(1)->can('permission')){
  echo "Auth user is allowed to perform this operation";
}

$role = Wovosoft\LaravelPermissions\Models\Roles::find(1);
if($role->hasAbility('permission')){
  echo "The Role with ID 1 is allowed to perform this operation";
}
bash
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="resources"
bash
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="migrations"
bash
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="seeds"
bash
php artisan migrate
bash
php artisan route:list