Hi @laravel dev, your Article Factory is using the wrong namespace of the model Article.
You should replace App\Article with App\Models\Article.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
M TRYING TO make articles using tinker but it gives this error: "PHP Error: Class 'App\Article' not found in ...\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Factories\Factory.php on line 625" i use this command to make it:
Article::factory()->count(5)->create();
Article.php:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
use HasFactory;
// protected $fillable = ['title', 'excerpt', 'body'];
protected $guarded = [];
public function user()
{
//
}
}
database>factories>ArticleFactory.php:
<?php
namespace Database\Factories;
use App\Article;
use Illuminate\Database\Eloquent\Factories\Factory;
class ArticleFactory extends Factory
{
protected $model = Article::class;
public function definition()
{
return [
'user_id' => factory(\App\User::class),
'title' => $faker->sentence,
'excerpt' => $faker->sentence,
'body' => $faker->paragraph
];
}
}
when i google error the i found to use to run "composer dump" and after running this command now it gives:
[!] Aliasing 'Article' to 'App\Models\Article' for this Tinker session.
You need to reshape your code a bit.
The problem above is that $faker is not available in this context. You will need to add $this keyword in order to obtain a reference to faker.
Your code shall look as follows:
<?php
namespace Database\Factories;
use App\Models\Article;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class ArticleFactory extends Factory
{
protected $model = Article::class;
public function definition()
{
return [
'user_id' => User::factory()->create()->id,
'title' => $this->faker->sentence,
'excerpt' => $this->faker->sentence,
'body' => $this->faker->paragraph
];
}
}
Yes, there are a lot of series which you can watch. I would start with my personal favourite Jeffrey Way:
https://laracasts.com/series/laravel-6-from-scratch
Please or to participate in this conversation.