- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\Role;
|
|
|
|
class RoleSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$roles = [
|
|
[
|
|
'name' => 'Admin',
|
|
'slug' => 'admin',
|
|
'description' => 'Full access to the entire system.',
|
|
'is_protected' => true,
|
|
],
|
|
[
|
|
'name' => 'Editor',
|
|
'slug' => 'editor',
|
|
'description' => 'Can manage pages and posts.',
|
|
'is_protected' => false,
|
|
],
|
|
[
|
|
'name' => 'Author',
|
|
'slug' => 'author',
|
|
'description' => 'Can manage their own posts.',
|
|
'is_protected' => false,
|
|
],
|
|
[
|
|
'name' => 'User',
|
|
'slug' => 'user',
|
|
'description' => 'Public-facing site viewer.',
|
|
'is_protected' => false,
|
|
],
|
|
];
|
|
|
|
foreach ($roles as $roleData) {
|
|
$role = Role::where('slug', $roleData['slug'])->first();
|
|
|
|
if ($role) {
|
|
// Only update name and description, avoid is_protected to bypass Eloquent check
|
|
$role->update([
|
|
'name' => $roleData['name'],
|
|
'description' => $roleData['description'],
|
|
]);
|
|
} else {
|
|
$role = Role::create($roleData);
|
|
}
|
|
|
|
// Assign permissions based on role slug
|
|
if ($role->slug === 'editor') {
|
|
$editorPermissions = \App\Models\Permission::whereIn('resource', ['pages', 'media', 'themes', 'posts', 'forms', 'navigation'])
|
|
->pluck('id');
|
|
$role->permissions()->sync($editorPermissions);
|
|
}
|
|
|
|
if ($role->slug === 'author') {
|
|
$authorPermissions = \App\Models\Permission::whereIn('resource', ['pages', 'media', 'posts'])
|
|
->whereIn('action', ['view', 'create', 'edit'])
|
|
->pluck('id');
|
|
$role->permissions()->sync($authorPermissions);
|
|
}
|
|
}
|
|
}
|
|
}
|