104 lines
3.9 KiB
PHP
104 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Block;
|
|
use App\Models\Channel;
|
|
use App\Models\Post;
|
|
use App\Models\Publication;
|
|
use App\Models\Prefix;
|
|
use App\Models\TaxonomyTerm;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
{
|
|
use WithoutModelEvents;
|
|
|
|
public function run(): void
|
|
{
|
|
$admin = User::factory()->create([
|
|
'name' => 'Admin',
|
|
'email' => 'admin@example.com',
|
|
'password' => bcrypt('password'),
|
|
]);
|
|
|
|
// Shared prefixes
|
|
$blogPrefix = Prefix::create(['slug' => 'blog']);
|
|
$newsPrefix = Prefix::create(['slug' => 'news']);
|
|
$postsPrefix = Prefix::create(['slug' => 'posts']);
|
|
|
|
$techEn = Channel::create([
|
|
'name' => 'Tech EN',
|
|
'hostname' => 'tech.example.com',
|
|
'locale' => 'en',
|
|
'taxonomy_slug' => 'topic',
|
|
'template' => 'default',
|
|
'meta_title' => 'Tech Blog',
|
|
'meta_description' => 'Technology articles in English.',
|
|
]);
|
|
|
|
$techDe = Channel::create([
|
|
'name' => 'Tech DE',
|
|
'hostname' => 'tech.example.de',
|
|
'locale' => 'de',
|
|
'taxonomy_slug' => 'thema',
|
|
'template' => 'default',
|
|
'meta_title' => 'Tech Blog DE',
|
|
'meta_description' => 'Technologie-Artikel auf Deutsch.',
|
|
]);
|
|
|
|
$lifeEn = Channel::create([
|
|
'name' => 'Life EN',
|
|
'hostname' => 'life.example.com',
|
|
'locale' => 'en',
|
|
'taxonomy_slug' => 'tag',
|
|
'template' => 'default',
|
|
'meta_title' => 'Life Blog',
|
|
'meta_description' => 'Lifestyle articles in English.',
|
|
]);
|
|
|
|
// Tech channels share 'blog' prefix (same URL path → different publications)
|
|
$techEn->prefixes()->attach([$blogPrefix->id, $newsPrefix->id]);
|
|
$techDe->prefixes()->attach([$blogPrefix->id]);
|
|
$lifeEn->prefixes()->attach([$postsPrefix->id]);
|
|
|
|
foreach ([$techEn, $techDe, $lifeEn] as $channel) {
|
|
TaxonomyTerm::factory()->count(4)->create(['channel_id' => $channel->id]);
|
|
}
|
|
|
|
// Posts shared between tech channels (published on both)
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$post = Post::create(['user_id' => $admin->id]);
|
|
|
|
foreach ([$techEn, $techDe] as $channel) {
|
|
$publication = Publication::factory()->published()->create([
|
|
'post_id' => $post->id,
|
|
'channel_id' => $channel->id,
|
|
]);
|
|
$publication->taxonomyTerms()->attach(
|
|
$channel->taxonomyTerms()->inRandomOrder()->limit(2)->pluck('id')
|
|
);
|
|
Block::factory()->create(['publication_id' => $publication->id, 'order' => 0]);
|
|
Block::factory()->image()->create(['publication_id' => $publication->id, 'order' => 1]);
|
|
Block::factory()->create(['publication_id' => $publication->id, 'order' => 2]);
|
|
}
|
|
}
|
|
|
|
// Posts exclusive to life channel
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$post = Post::create(['user_id' => $admin->id]);
|
|
|
|
$publication = Publication::factory()->published()->create([
|
|
'post_id' => $post->id,
|
|
'channel_id' => $lifeEn->id,
|
|
]);
|
|
$publication->taxonomyTerms()->attach(
|
|
$lifeEn->taxonomyTerms()->inRandomOrder()->limit(2)->pluck('id')
|
|
);
|
|
Block::factory()->create(['publication_id' => $publication->id, 'order' => 0]);
|
|
Block::factory()->image()->create(['publication_id' => $publication->id, 'order' => 1]);
|
|
}
|
|
}
|
|
}
|