Laravel 5:如何添加播种器类以自动加载? [英] Laravel 5: How can I add seeder class to autoload?
问题描述
我遵循以下文档: http://laravel.com/docs/master/migrations#database-seeding
我在DatabaseSeeder
附近放置了UserTableSeeder
文件.在resources/database/seeds/
文件夹中.
这些文件没有名称空间(仅app/
中的类具有名称空间).
I placed UserTableSeeder
file near DatabaseSeeder
. In resources/database/seeds/
folder.
These files are without namespaces (only classes in app/
are namespaced).
当然有一个例外:exception 'ReflectionException' with message 'Class UserTableSeeder does not exist'
解决此问题的最佳方法是什么?
What is the best way to solve this problem?
推荐答案
默认的Laravel 5项目在其composer.json
中定义了一个类映射:
The default Laravel 5 project has a classmap defined in its composer.json
:
{
// ...
"autoload": {
"classmap": [
"database"
],
// ...
}
}
每次在database
目录中添加或删除类以更新Composer自动加载器时,
运行composer dump
Run composer dump
every time you add or remove a class on your database
directory to update the Composer autoloader
参考: https://github.com/laravel/laravel/blob/develop/composer.json
这篇关于Laravel 5:如何添加播种器类以自动加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!