Home > Mobile >  php artisan migarate:fresh -seed keep getting error
php artisan migarate:fresh -seed keep getting error

Time:09-06

i keep getting this error whenever i tried to use php artisan migarate:fresh -seed. What should i do?

   Error 

  Class "Database\Seeders\User" not found

  at D:\database\seeders\UserTableSeeder.php:16
    `enter code here` 12▕      * @return void
     13▕      */
     14▕     public function run()
     15▕     {
  ➜  16▕         User::factory()->create([
     17▕             'name'      =>  'Admin',
     18▕             'email'     =>  '[email protected]',
     19▕             'password'  =>  bcrypt('password'),
     20▕             'type'      =>  User::ADMIN,

CodePudding user response:

A namespace is failing, try this instead.

In your User.php model

Ensure the class has this trait included:

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory; // <-- Add this

class User
{
    use HasFactory; // <-- Add this
    ...
}

In your user seeder

public function run()
{
    \App\Models\User::factory()->create([ // <-- Reference the user this way
        'name'      =>  'Admin',
        'email'     =>  '[email protected]',
        'password'  =>  bcrypt('password'),
        'type'      =>  User::ADMIN,
        ...
    ]);
}
  • Related