Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

melmoniry's avatar

Trait 'Illuminate\Database\Eloquent\Factories\HasFactory' not found

my problem is whenever I try importing HasFactory it throws the following error

Trait 'Illuminate\Database\Eloquent\Factories\HasFactory' not found

this is the model throwing the error :

 use Illuminate\Contracts\Auth\MustVerifyEmail;

use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Foundation\Auth\User as Authenticatable;

use Illuminate\Notifications\Notifiable;

use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable

{

    use HasFactory, Notifiable, HasRoles;



    protected $fillable = [

        'name',

        'email',

        'password',

    ];



   

    protected $hidden = [

        'password',

        'remember_token',

    ];



    protected $casts = [

        'email_verified_at' => 'datetime',

    ];

}  ```
0 likes
10 replies
iyashpal's avatar

try composer dump-autoload command.

1 like
melmoniry's avatar

didn't work I've tried it, tried composer update, composer dump nothing seems to be working

adiputra22's avatar

hi @melmoniry , not found meaning that class or trait is not in your project. can you check it in vendor folder with path Laravel > Framework > src > Illuminate > Database > Eloquent > Factories ?

if in those folder you not have that Trait class, try to composer dump-autoload or maybe you need re-install your Laravel project.

Btw, what is your laravel version bro?

1 like
melmoniry's avatar

Hi @adiputra22 thanks for helping, my laravel version is 7 30 3

I actually do not have the factories folder after navigating to it, it's not there I've tried using composer dump-autoload for it to appear but it didn't not sure why

adiputra22's avatar

how if you running composer install?

whats php version do you use?

melmoniry's avatar

it gives nothing to install, maybe you wanna have a look at my composer,json file? php version is 7,2,32

adiputra22's avatar

yes please.

or maybe sometime i remove all vendor folder. then i try to re-install again with composer install

melmoniry's avatar

I've successfully upgraded to laravel 8 and it's finally working, I think it has to do with having used functionalities only supported by laravel 8 thanks for your help

Please or to participate in this conversation.