PHP artisan db seed doesen’t works please find solution

  laravel, php

So i did in MembersSeeder

Members ::factory(10)->create();

While in Factory i did

'user_id' => $this->faker->idnumber, 'address' => $this->faker->address

And the good the least Members Models i did

protected $fillable = ['user_id', 'address'];

Heres the code.

Error downest below.

Please find a fix that works ( change )

<?php

namespace DatabaseFactories;

use AppModelsModel;
use IlluminateDatabaseEloquentFactoriesFactory;

class MembersFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Model::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
        'user_id' => $this->faker->idnumber,
        'address' => $this->faker->address
        ];
    }
}
<?php

namespace DatabaseSeeders;

use IlluminateDatabaseSeeder;
use AppModelsMembers;
class MembersSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Members ::factory(10)->create();    }
}
<?php

namespace AppModels;

use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;

class Members extends Model
{
    use HasFactory;

    protected $fillable = ['user_id', 'address'];
}

ERROR That i get

[email protected] igel % php artisan db:seed MembersSeeder

   Error 

  Class 'AppModelsModel' not found

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:628
    624▕     public function newModel(array $attributes = [])
    625▕     {
    626▕         $model = $this->modelName();
    627▕ 
  ➜ 628▕         return new $model($attributes);
    629▕     }
    630▕ 
    631▕     /**
    632▕      * Get the name of the model that is generated by the factory.

      +2 vendor frames 
  3   database/seeders/MembersSeeder.php:16
      IlluminateDatabaseEloquentFactoriesFactory::create()

      +22 vendor frames 
  26  artisan:37
      IlluminateFoundationConsoleKernel::handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
[email protected] igel % 

Source: Ask PHP

LEAVE A COMMENT