From 36b7343487e9b65533e6422c7a2c39b4adbdaa69 Mon Sep 17 00:00:00 2001 From: Anastas Mironov Date: Tue, 23 Jul 2024 20:06:04 +0900 Subject: [PATCH] feat: add ArticleFactory.php --- composer.json | 5 +++-- database/factories/ArticleFactory.php | 21 +++++++++++++++------ database/seeders/ArticleSeeder.php | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 database/seeders/ArticleSeeder.php diff --git a/composer.json b/composer.json index be8bc8b..902edda 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "filament/filament": "^3.0-stable", "illuminate/contracts": "^10.0|^11.0", "ibecsystems/admin-kit-core": "^3.1", - "ibecsystems/admin-kit-seo": "^3.0", + "ibecsystems/admin-kit-seo": "^3.4", "spatie/laravel-package-tools": "^1.14.0", "spatie/laravel-data": "^4.5", "spatie/laravel-json-api-paginate": "^1.13", @@ -45,7 +45,8 @@ "autoload": { "psr-4": { "AdminKit\\Articles\\": "src/", - "AdminKit\\Articles\\Database\\Factories\\": "database/factories/" + "AdminKit\\Articles\\Database\\Factories\\": "database/factories/", + "AdminKit\\Articles\\Database\\Seeders\\": "database/seeders/" } }, "autoload-dev": { diff --git a/database/factories/ArticleFactory.php b/database/factories/ArticleFactory.php index 2ee1c6d..c16188f 100644 --- a/database/factories/ArticleFactory.php +++ b/database/factories/ArticleFactory.php @@ -3,6 +3,7 @@ namespace AdminKit\Articles\Database\Factories; use AdminKit\Articles\Models\Article; +use AdminKit\Core\Facades\AdminKit; use Illuminate\Database\Eloquent\Factories\Factory; class ArticleFactory extends Factory @@ -11,13 +12,21 @@ class ArticleFactory extends Factory public function definition() { + $title = $content = $shortContent = []; + foreach (AdminKit::locales() as $locale) { + $title[$locale] = fake()->word()."_$locale"; + $content[$locale] = fake()->randomHtml(); + $shortContent[$locale] = fake()->text(20); + } + return [ - 'title' => $this->faker->realText(30), - 'slug' => $this->faker->slug, - 'content' => $this->faker->randomHtml(), - 'short_content' => $this->faker->randomHtml(), - 'pinned' => $this->faker->boolean(), - 'published_at' => $this->faker->dateTime(), + 'title' => $title, + 'slug' => fake()->slug(), + 'content' => $content, + 'short_content' => $shortContent, + 'pinned' => fake()->boolean(10), + + 'published_at' => fake()->boolean(90) ? fake()->dateTimeThisYear() : null, ]; } } diff --git a/database/seeders/ArticleSeeder.php b/database/seeders/ArticleSeeder.php new file mode 100644 index 0000000..856b0ac --- /dev/null +++ b/database/seeders/ArticleSeeder.php @@ -0,0 +1,22 @@ +has(SEO::factory()) + ->create() + ->each(function (Article $model) { + $model->addMedia(File::image($model->id.'_'.str()->random(10).'.jpg'))->toMediaCollection(); + $model->seo->addMedia(File::image($model->id.'_'.str()->random(10).'.jpg'))->toMediaCollection(); + }); + } +}