沃梦达 / 编程问答 / php问题 / 正文

Laravel 5 Seeder 类不存在

Laravel 5 Seeder Class Does Not Exist(Laravel 5 Seeder 类不存在)

本文介绍了Laravel 5 Seeder 类不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个全新的 Laravel 安装.我已经从一个 Laravel 项目的 github 存储库中转移了代码,版本相同 (5.3).

I have a fresh Laravel installation. I have moved over code from a github repository that is a Laravel project, same version (5.3).

一切正常,但由于某种原因数据库种子无法运行.

Everything works fine, except for some reason the database seeds wont' run.

例如,我可以在新的 Laravel 安装中从 github 加载的迁移中迁移,就像我在最初将迁移推送到 github 的服务器上一样.

For example, I can migrate from the github loaded migrations in the new Laravel installation, just as I would on the server that pushed the migrations to github in the first place.

但是我不能做php artisan db:seed,这意味着我漂亮的小数据库是空的!>:(

But I can't do php artisan db:seed, which means my beautiful little database is empty! >:(

我得到:ReflectionException 类不存在

我尝试过的:

  1. php 工匠优化
  2. php artisan clear:cache
  3. 作曲家清除缓存
  4. 作曲家转储自动加载

这些都没有解决我的问题.DatabaseSeeder 中的所有内容都拼写正确,并且类 - 确实存在,它们在我的其他服务器上工作正常,而且,由于 Github,这个全新安装现在具有与我的原始服务器相同的所有文件.

None of which have solved my problem. Everything in DatabaseSeeder is spelled correctly and the classes -do- exist, they work fine on my other server, and again, this fresh install now has all the same files as my origin server, thanks to Github.

DatabaseSeeder.php:

DatabaseSeeder.php:

<?php

use IlluminateDatabaseSeeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(UserTableSeeder::class);
    }
}

编辑 - 堆栈跟踪:

2017-06-14 19:11:00] local.ERROR: ReflectionException: Class UserTablesSeeder does not exist in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:749
Stack trace:
#0 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(749): ReflectionClass->__construct('UserTablesSeede...')
#1 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): IlluminateContainerContainer->build('UserTablesSeede...', Array)
#2 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): IlluminateContainerContainer->make('UserTablesSeede...', Array)
#3 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(55): IlluminateFoundationApplication->make('UserTablesSeede...')
#4 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(43): IlluminateDatabaseSeeder->resolve('UserTablesSeede...')
#5 /var/www/laravel/database/seeds/DatabaseSeeder.php(14): IlluminateDatabaseSeeder->call('UserTablesSeede...')
#6 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(63): DatabaseSeeder->run()
#7 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2292): IlluminateDatabaseConsoleSeedsSeedCommand->IlluminateDatabaseConsoleSeeds{closure}()
#8 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(64): IlluminateDatabaseEloquentModel::unguarded(Object(Closure))
#9 [internal function]: IlluminateDatabaseConsoleSeedsSeedCommand->fire()
#10 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#11 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): IlluminateContainerContainer->call(Array)
#12 /var/www/laravel/vendor/symfony/console/Command/Command.php(261): IlluminateConsoleCommand->execute(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#13 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): SymfonyComponentConsoleCommandCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#14 /var/www/laravel/vendor/symfony/console/Application.php(817): IlluminateConsoleCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#15 /var/www/laravel/vendor/symfony/console/Application.php(185): SymfonyComponentConsoleApplication->doRunCommand(Object(IlluminateDatabaseConsoleSeedsSeedCommand), Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#16 /var/www/laravel/vendor/symfony/console/Application.php(116): SymfonyComponentConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#17 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#18 /var/www/laravel/artisan(35): IlluminateFoundationConsoleKernel->handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#19 {main}  

推荐答案

试运行

composer dump-autoload

尤其是如果您最近编辑了播种器文件的名称

especially if you have recently edited the name of your seeder file

这篇关于Laravel 5 Seeder 类不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Laravel 5 Seeder 类不存在