forked from eatvio/eatvio-infra
04 10 2023 snapshot
This commit is contained in:
45
database/factories/BlogPostFactory.php
Normal file
45
database/factories/BlogPostFactory.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Models\BlogPost;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\BlogPost>
|
||||
*/
|
||||
class BlogPostFactory extends Factory
|
||||
{
|
||||
protected $model = BlogPost::class;
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$imagePath = storage_path('app/public');
|
||||
$curImage = $this->faker->image($imagePath . "/blog_posts", 360, 360, 'animals', true, true, 'cats', true, 'jpg');
|
||||
$curImage = Str::replace($imagePath, '', $curImage);
|
||||
return [
|
||||
'state' => $this->faker->randomElement(['active', 'archived']),
|
||||
'image' => $curImage,
|
||||
'description' => $this->faker->realText($this->faker->numberBetween(100, 200)),
|
||||
'youtube_url' => $this->faker->url(),
|
||||
'created_at' => $this->faker->dateTimeBetween('-1 week', '+1 week'),
|
||||
'updated_at' => $this->faker->dateTimeBetween('-1 week', '+1 week'),
|
||||
'title'=> $this->faker->realText($this->faker->numberBetween(10, 20)),
|
||||
];
|
||||
}
|
||||
|
||||
public function some()
|
||||
{
|
||||
User::orderBy('created_at', 'desc')->limit(20)->get()->map(function($user) {
|
||||
$newBlogPosts = BlogPost::factory()->count(3)->create();
|
||||
$newBlogPosts->map(function ($post) use ($user) {
|
||||
$user->author_of_blog_post()->attach($post->id);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user