45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\MediaDirectory;
|
|
|
|
class DemoMediaLibrarySeeder extends Seeder
|
|
{
|
|
public function run(DemoContext $ctx): void
|
|
{
|
|
if (MediaDirectory::where('created_by', $ctx->userId)->exists()) {
|
|
return;
|
|
}
|
|
|
|
$directories = [
|
|
['name' => 'Documents', 'slug' => 'documents', 'children' => ['Contracts', 'Proposals', 'Reports']],
|
|
['name' => 'Invoices', 'slug' => 'invoices', 'children' => ['Sales', 'Purchase', 'Returns']],
|
|
['name' => 'HR Files', 'slug' => 'hr-files', 'children' => ['Certifications', 'Requirements', 'ID Cards']],
|
|
['name' => 'Marketing', 'slug' => 'marketing', 'children' => ['Brochures', 'Social Media']],
|
|
['name' => 'Company', 'slug' => 'company', 'children' => ['Logos', 'Templates']],
|
|
];
|
|
|
|
foreach ($directories as $dir) {
|
|
$parent = MediaDirectory::create([
|
|
'name' => $dir['name'],
|
|
'slug' => $dir['slug'],
|
|
'parent_id' => null,
|
|
'creator_id' => $ctx->userId,
|
|
'created_by' => $ctx->userId,
|
|
]);
|
|
|
|
foreach ($dir['children'] as $childName) {
|
|
MediaDirectory::create([
|
|
'name' => $childName,
|
|
'slug' => strtolower(str_replace(' ', '-', $childName)),
|
|
'parent_id' => $parent->id,
|
|
'creator_id' => $ctx->userId,
|
|
'created_by' => $ctx->userId,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|