Hi everyone,
I'm getting the following error when trying to create article with the factory method as a part of the laravel from scratch course. I'm trying to create 10 random articles from tinker.
>>> Article::factory()->count(10)->create();
PHP Error: Class 'Database/Factories/App/Models/User' not found in C:/freshproject/database/factories/ArticleFactory.php on line 25
I've triple and quadruple checked everything and I can't seem to find why the file isn't being drawn from the root directory - seems to be the only thing wrong. I've had to change the original code form the course as I found that the functionality is different in laravel 8. I'm assuming i'm missing something in translation. This is my factory code:
<?php
namespace Database\Factories;
use App\Models\Article;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class ArticleFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Article::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'user_id' => function () {
return \App\Models\User::factory();
},
'title' => $faker->sentence,
'excerpt' => $faker->paragraph,
'body' => $faker->paragraphs(5)
];
}
}
Any help would be appreciated!