当我尝试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