當我嘗試db:seed時,從命令提示符處獲取該錯誤。我確實運行了composer dump
,並確保Seeder命名空間位於我的種子文件中。類'用戶'不存在?
我不明白爲什麼它告訴我的User類(我敢肯定,是指模型)不存在,當我在應用程序\ user.php的
以下<?php namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
}
這裏是數據庫\種子我UserTableSeeder.php文件
<?php
use Illuminate\Database\Seeder;
class UserTableSeeder extends Seeder
{
public function run()
{
DB::table('users')->delete();
User::create(array(
'username' => 'admin',
'password' => Hash::make('secret')
));
}
}
我知道,這些字段不會在$可填寫的變量相匹配,但我不認爲這會導致類甚至不被認可ZED。在我可以種子之前,我需要在這個文件中添加一個create()函數嗎?
這裏是我的數據庫(時間戳)_create_users_table.php的好措施:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('username');
$table->string('password');
$table->rememberToken()->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
任何想法怎麼回事?另外,通過使用我自己的Users表,我是否正在使用內置的auth和whatnot?
你是不是在播種機中的意思?在遷移中沒有任何對'User'的引用。 – 2015-04-06 01:26:34
對不起,是的,你有錯誤的db:seed命令。我現在在路上,只是彈出。 – 2015-04-06 01:27:55