PHP code example of chiiya / filament-access-control
1. Go to this page and download the library: Download chiiya/filament-access-control 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/ */
chiiya / filament-access-control example snippets
use Chiiya\FilamentAccessControl\FilamentAccessControlPlugin;
return $panel
->default()
->id('admin')
->path('admin')
->plugin(FilamentAccessControlPlugin::make())
class ProductPolicy
{
public function viewAny(FilamentUser $user): bool
{
return $user->can('products.view');
}
// ...
}
use Chiiya\FilamentAccessControl\Traits\AuthorizesPageAccess;
class MyPage extends Page
{
use AuthorizesPageAccess;
public static string $permission = 'my-page.view';
public function mount(): void
{
static::authorizePageAccess();
}
}
use Chiiya\FilamentAccessControl\Models\FilamentUser;
use Chiiya\FilamentAccessControl\Contracts\AccessControlUser;
use Filament\Models\Contracts\FilamentUser as FilamentUserInterface;
use Filament\Models\Contracts\HasName;
use Illuminate\Foundation\Auth\User as Authenticatable;
class CustomFilamentUser extends FilamentUser
{
// ...
}
// Or alternatively
class CustomFilamentUser extends Authenticatable implements AccessControlUser, FilamentUserInterface, HasName
{
// ...
}
/*
|--------------------------------------------------------------------------
| Resources
|--------------------------------------------------------------------------
| Resources used for managing users, roles and permissions.
*/
'resources' => [
'user' => FilamentUserResource::class,
'role' => RoleResource::class,
'permission' => PermissionResource::class,
]
public static function insertBeforeFormSchema(): array
{
return [];
}
public static function insertAfterFormSchema(): array
{
return [];
}
public static function insertBeforeTableSchema(): array
{
return [];
}
public static function insertAfterTableSchema(): array
{
return [];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.