Laravel Seed db:seed [Symfony \ Component \ Debug \ Exception \ FatalThrowableError]致命错误:Class' model'未找到

时间:2016-04-03 15:58:54

标签: symfony composer-php laravel-5.1

我正在使用FactoryModel工具为此填充数据库执行以下操作:

创建表:

Php artisan make:model “Users” –m 

Up mysql:

php artisan migrate

迁移:

{

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password',60);
        $table->enum('type',['Miembro','Administrador'])->default('Miembro');
        $table->rememberToken();
        $table->timestamps();
    });
}


public function down()
{
    Schema::drop('users');
}
}

模型用户

{
 use Authenticatable, Authorizable, CanResetPassword; 

 protected $table = 'users'; 

 protected $fillable = ['name', 'email', 'password','type']; 

protected $hidden = [
'password', 'remember_token',
];
}

在ModelFactory.php中;

$factory->define(App\User::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'email' => $faker->safeEmail,
'password' => bcrypt('123'),
'type' => 'administrador',
'remember_token' => str_random(10),
];

});

在dataseSeeder.php中:

 public function run()
{
model::unguard();

factory('App\User','Administrador',3)->create();

model::reguard();

}

迁移BD:

  php artisan db:seed 

错误:     [Symfony的\元器件\调试\异常\ FatalThrowableError]     致命错误:Class' model'找不到

感谢您的帮助

DGR

1 个答案:

答案 0 :(得分:0)

模型类名称应为“User”而不是“Users”。 然后,ModelFactory.php中未设置工厂定义的名称,它应如下所示:

$factory->define(App\User::class, 'Administrador', function (Faker\Generator $faker) {
    return [
    'name' => $faker->name,
    'email' => $faker->safeEmail,
    'password' => bcrypt('123'),
    'type' => 'administrador',
    'remember_token' => str_random(10),
    ];
});