我正在尝试一个基本的 php artisan db:seed 迁移我的数据库后,但它一直在 cmd 中返回标题错误 -[ReflectionException] Class ‘UserTableSeeder’ 不存在
我尝试过的事情
- 更改 ‘UserTableSeeder.php’ 文件 ‘namespace Database\seeds;’ 的命名空间和’使用数据库\种子\用户表种子;’在“DatabaseSeeder.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('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
下面是 UserTableSeeder.php
<?php
use App\User;
use Illuminate\Database\Seeder;
class UserTableSeeder extends Seeder {
public function run()
{
DB::table('users')->delete();
User::create(['email' => 'foo@bar.com']);
}
}
下面是 DatabaseSeeder.php
<?php
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');
}
}
原文由 thirdriver 发布,翻译遵循 CC BY-SA 4.0 许可协议
在你的类中添加命名空间。
之后运行 composer dump-autoload