<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rickgoemans / laravel-permission-service example snippets
use Rickgoemans\LaravelPermissionService\Enums\PermissionAction;
// config for Rickgoemans/LaravelPermissionService
return [
/*
* The separator that's being used between the model it's name and the action.
*/
'separator' => '.',
/*
* The names of the methods that reflect the action.
*/
'action_names' => [
PermissionAction::VIEW->value => 'view',
PermissionAction::CREATE->value => 'create',
PermissionAction::UPDATE->value => 'update',
PermissionAction::DELETE->value => 'delete',
PermissionAction::RESTORE->value => 'restore',
PermissionAction::FORCE_DELETE->value => 'force_delete',
],
/*
* The package prefix that is being used for package permissions.
*/
'package_prefix' => 'package',
/*
* The application prefix that is being used for application permissions.
*/
'application_prefix' => 'app',
];
use App\Models\Activity;
use App\Models\Customer;
use App\Models\User;
use Rickgoemans\LaravelPermissionService\Services\PermissionService;
return [
'all' => [
PermissionService::viewPermission(Activity::class),
...PermissionService::crudPermissions(User::class),
...PermissionService::crudPermissions(Customer::class, true, true),
...PermissionService::packagePermission('nova'),
...PermissionService::packagePermission('admin_panel'),
],
];
namespace App\Policies;
use App\Models\Example;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Auth\Access\Response;
class ExamplePolicy extends Controller {
use HandlesAuthorization;
public function viewAny(User $auth): Response|bool
{
return $auth->can(PermissionService::viewPermission(Example::class));
}
public function view(User $auth, Example $example): Response|bool
{
return $auth->can(PermissionService::viewPermission(Example::class));
}
public function create(User $auth): Response|bool
{
return $auth->can(PermissionService::createPermission(Example::class));
}
public function update(User $auth, Example $example): Response|bool
{
return $auth->can(PermissionService::updatePermission(Example::class));
}
public function delete(User $auth, Example $example): Response|bool
{
return $auth->can(PermissionService::deletePermission(Example::class));
}
public function restore(User $auth, Example $example): Response|bool
{
return $auth->can(PermissionService::restorePermission(Example::class));
}
public function forceDelete(User $auth, Example $example): Response|bool
{
return $auth->can(PermissionService::forceDeletePermission(Example::class));
}
}