我正在尝试了解laravel。我不忙于播种,我不断收到以下错误:
[ReflectionException]
Class UserTableSeeder does not exist
我做了什么:
用户类
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', 'username', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
}
CreateUserTable 迁移:
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('name');
$table->string('username');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
UserTableSeeder
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class UserTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB:table('users')->delete();
User::create(array(
'name' => 'Graham Neal',
'username' => 'Graham',
'email' => 'grahamneal1991@gmail.com',
'password' => Hash::make('0258456'),
));
}
}
数据库播种机
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// $this->call(UserTableSeeder::class);
$this->call('UserTableSeeder');
Model::reguard();
}
}
在数据库播种机中,我尝试了以下操作:
$this->call('UserTableSeeder');
$this->call('UserTableSeeder::User');
$this->call('App/UserTableSeeder');
$this->call('App/UserTableSeeder::User');
我知道它找不到课程,但我对找出原因一无所知?我搜索了谷歌并找到了其他人出错的其他地方,但我似乎没有同样的错误。希望这不是一个非常愚蠢的问题。
编辑*
如果我做 composer dump-autoload 我得到上述错误和以下异常跟踪:
[RuntimeException]
Could not scan for classes inside "user" which does not appear to be a file
nor a folder
在我手动将类添加到 composer.json 文件后,出现此错误。
现在,如果我尝试使用 php artisan db:seed 我得到另一个错误:
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined function table()