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转储自动加载
  • 在运行
    db:seed
    函数之前,php转储自动加载
  • 回滚迁移,然后重新运行它
  • 回滚迁移,然后使用
    --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