Answer the question
In order to leave comments, you need to log in
$factory->define?
I have an error when creating factories (laravel 8) here is the code
$factory->define(\App\Models\BlogPost::class, function(Faker $faker)){
$title = $faker->create()->sentence(rand(3,8),true);
$txt = $faker->create()->realText(rand(1000,4000));
$isPublished = rand(1,5) > 1;
$data = [
'category_id' => rand(1,10),
'user_id' => (rand(1,5) == 5) ? 1 : 2,
'title' => $title,
'slug' => Str::of($title)->slug(),
'excerpt' => $faker->create()->text(rand(40,100)),
'content_raw' => $txt,
'content_html' => $txt,
'is_published' => $isPublished,
'published_at' => $isPublished ? $faker->create()->dateTimeBetween('-2 months','-1 days'):null,
'created_at' => $faker->create()->dateTimeBetween('-3 months','-2 months'),
'updated_at' => $faker->create()->dateTimeBetween('-3 months','-2 months'),
];
return $data;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question