PHP code example of deifhelt / laravel-permissions-manager
1. Go to this page and download the library: Download deifhelt/laravel-permissions-manager 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/ */
deifhelt / laravel-permissions-manager example snippets
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasRoles;
}
use Deifhelt\LaravelPermissionsManager\Facades\Permissions;
use Deifhelt\LaravelPermissionsManager\Database\Seeders\RolesAndPermissionsSeeder;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
$this->call(RolesAndPermissionsSeeder::class);
}
}
use Deifhelt\LaravelPermissionsManager\Traits\HasPermissionCheck;
class PostPolicy
{
use HasPermissionCheck;
public function viewAny(User $user): bool
{
return $this->checkPermission($user, 'read posts');
}
public function update(User $user, Post $post): bool
{
// Checks permission AND ownership (user_id)
return $this->checkPermission($user, 'update posts', $post);
}
}