簡體   English   中英

Laravel Seed db:seed [Symfony \\ Component \\ Debug \\ Exception \\ FatalThrowableError]致命錯誤:找不到類'model'

[英]Laravel Seed db:seed [Symfony\Component\Debug\Exception\FatalThrowableError] Fatal error: Class 'model' not found

我正在使用FactoryModel工具為此填充數據庫,請執行以下操作:

創建表:

Php artisan make:model “Users” –m 

上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 \\ Component \\ Debug \\ Exception \\ FatalThrowableError]致命錯誤:找不到類“模型”

我感謝您的幫助

DGR

模型類名稱應為“ 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),
    ];
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM