mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-11-13 01:28:51 +01:00
89 lines
2.0 KiB
PHP
89 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Seeders\Auth\Role;
|
|
|
|
use App\Models\Auth\Permission;
|
|
use App\Models\Auth\Role;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Arr;
|
|
|
|
/**
|
|
* Class RoleSeeder.
|
|
*/
|
|
class RoleSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$this->call(AdminSeeder::class);
|
|
$this->call(WikiEditorRoleSeeder::class);
|
|
$this->call(WikiViewerRoleSeeder::class);
|
|
$this->call(PlaylistUserRoleSeeder::class);
|
|
}
|
|
|
|
/**
|
|
* Configure role with resource abilities.
|
|
*
|
|
* @param Role $role
|
|
* @param string $resource
|
|
* @param array<int, string> $abilities
|
|
* @return void
|
|
*/
|
|
protected function configureResource(Role $role, string $resource, array $abilities): void
|
|
{
|
|
$permissions = Arr::map($abilities, fn (string $ability) => Permission::findOrCreate("$ability $resource"));
|
|
|
|
$role->givePermissionTo($permissions);
|
|
}
|
|
|
|
/**
|
|
* Configure role with abilities.
|
|
*
|
|
* @param Role $role
|
|
* @param array<int, string> $abilities
|
|
* @return void
|
|
*/
|
|
protected function configureAbilities(Role $role, array $abilities): void
|
|
{
|
|
$permissions = Arr::map($abilities, fn (string $ability) => Permission::findOrCreate($ability));
|
|
|
|
$role->givePermissionTo($permissions);
|
|
}
|
|
|
|
/**
|
|
* Get CRUD abilities for resource.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
protected function crudAbilities(): array
|
|
{
|
|
return [
|
|
'view',
|
|
'create',
|
|
'update',
|
|
'delete',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get extended CRUD abilities for soft-delete resource.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
protected function extendedCrudAbilities(): array
|
|
{
|
|
return array_merge(
|
|
$this->crudAbilities(),
|
|
[
|
|
'restore',
|
|
],
|
|
);
|
|
}
|
|
}
|