Skip to content

Commit

Permalink
Merge pull request #14 from IBEC-BOX/feat/article-factory
Browse files Browse the repository at this point in the history
feat: add ArticleFactory.php
  • Loading branch information
ast21 authored Jul 23, 2024
2 parents 685798f + 36b7343 commit 32fbd95
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
21 changes: 15 additions & 6 deletions database/factories/ArticleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
];
}
}
22 changes: 22 additions & 0 deletions database/seeders/ArticleSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace AdminKit\Articles\Database\Seeders;

use AdminKit\Articles\Models\Article;
use AdminKit\SEO\Models\SEO;
use Illuminate\Database\Seeder;
use Illuminate\Http\Testing\File;

class ArticleSeeder extends Seeder
{
public function run(): void
{
Article::factory(10)
->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();
});
}
}

0 comments on commit 32fbd95

Please sign in to comment.