Php 类别';用户';找不到
因此,在迁移数据库之后,我尝试了一个基本的Php 类别';用户';找不到,php,laravel-5,laravel-artisan,Php,Laravel 5,Laravel Artisan,因此,在迁移数据库之后,我尝试了一个基本的php artisan db:seed,但它始终在cmd-[Symfony\Component\Debug\Exception\FatalErrorException]类“User”中返回标题错误,未找到该类 我尝试过的事情 更新类后php转储自动加载 在运行db:seed函数之前,php转储自动加载 回滚迁移,然后重新运行它 回滚迁移,然后使用--seed语法重新运行它 更改“用户”文件的命名空间 下面是迁移过程 <?php use Ill
php artisan db:seed
,但它始终在cmd-[Symfony\Component\Debug\Exception\FatalErrorException]类“User”中返回标题错误,未找到该类
我尝试过的事情
- 更新类后php转储自动加载
- 在运行
函数之前,php转储自动加载db:seed
- 回滚迁移,然后重新运行它
- 回滚迁移,然后使用
语法重新运行它--seed
- 更改“用户”文件的命名空间
<?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');
}
}
在数据库种子程序中,在根命名空间中调用类User
。因此,它尝试加载类User
。但是,您的类User
的定义位于命名空间App
中。因此,您应该在DatabaseSeeder
中使用App\User
,或者在文件顶部添加use App\User代码>
DatabaseSeeder
<?php
use App\User;
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');
$this->call('UserTableSeeder');
Model::reguard();
}
}
class UserTableSeeder extends Seeder
{
public function run()
{
DB::table('users')->delete();
User::create(['email' => 'John@doe.com']);
}
}
另一方面,我发现调试artisan输出非常有用。您应该使用标志-vvv
,该标志为输出消息(包括完整的堆栈跟踪)添加了极其详细的内容
php artisan migrate -vvv
如果使用App\User代码>不起作用,然后像这样放置使用light\Foundation\Auth\User代码>@AshwaniPanwar谢谢你这是我的问题,并为我解决了它<代码>使用Illumb\Foundation\Auth\User代码>是我需要的
<?php
use App\User;
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');
$this->call('UserTableSeeder');
Model::reguard();
}
}
class UserTableSeeder extends Seeder
{
public function run()
{
DB::table('users')->delete();
User::create(['email' => 'John@doe.com']);
}
}
use Illuminate\Foundation\Auth\User;
php artisan migrate -vvv