[英]Laravel 5 class DatabaseSeeder not found when running php Artisan db:seed
I'm new to Laravel, When I run php artisan db:seed i recieve the following message: 我是Laravel的新手,当我运行php artisan db:seed时,我收到以下消息:
[ReflectionException] Class DatabaseSeeder does not exist
[ReflectionException]类DatabaseSeeder不存在
I already have run composer dump-autoload sadly without any result. 我已经不幸地已经运行了作曲家dump-autoload而没有任何结果。 My class is located in the default folder /seeds
我的课位于默认文件夹/ seeds中
The code from the class: 来自该类的代码:
<?php namespace database\seeds;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\User;
use App\Country;
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call('CountryTableSeeder');
$this->call('UserTableSeeder');
}
}
class UserTableSeeder extends Seeder {
public function run() {
DB::table('users');
User::Create(['username' => 'Bart', 'email'=>'bart@example.com', 'password' => Hash::make('password')]);
}
}
class CountryTableSeeder extends Seeder {
public function run() {
DB::table('country');
Country::Create(['country_name' => 'Nederlander']);
}
}
What I'm doing wrong? 我做错了什么?
First you should remove namespace database\\seeds;
首先,您应该删除
namespace database\\seeds;
as @JoeCoder suggested in comment. 正如@JoeCoder在评论中建议的那样。
And the second thing is that you should not put many classes inside one file (as you probably did looking at your question). 第二件事是,您不应将多个类放在一个文件中(就像您在看问题时所做的那样)。 Each class should be placed in separate file.
每个类应放在单独的文件中。
if you've tried everything else and still getting Class DatabaseSeeder does not exist
, take a look at your composer.json
如果您已经尝试了所有其他方法,但是仍然
Class DatabaseSeeder does not exist
,请查看composer.json
There should be a section that looks something like: 应该有一个类似于以下内容的部分:
"autoload": {
"classmap": [
"app/Library",
"app/Models"
],
...
You should add two more lines here to tell autoloader where else it should look for your classes. 您应该在这里再添加两行,以告诉自动加载器在其他地方查找您的类。
So final result will be: 因此最终结果将是:
"autoload": {
"classmap": [
"app/Library",
"app/Models",
"database/seeds",
"database/migrations"
],
...
This will add both seeds
and migrations
directory to your autoloader class path. 这会将
seeds
和migrations
目录都添加到您的自动加载器类路径中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.