Laravel 5: How can I add seeder class to autoload?

∥☆過路亽.° 提交于 2020-03-21 12:40:12

问题


I follow the docs: http://laravel.com/docs/master/migrations#database-seeding

I placed UserTableSeeder file near DatabaseSeeder. In resources/database/seeds/ folder.
These files are without namespaces (only classes in app/ are namespaced).

Of course there is an exception: exception 'ReflectionException' with message 'Class UserTableSeeder does not exist'

What is the best way to solve this problem?


回答1:


The default Laravel 5 project has a classmap defined in its composer.json:

{
    // ...
    "autoload": {
        "classmap": [
            "database"
        ],
        // ...
    }
}

Run composer dump every time you add or remove a class on your database directory to update the Composer autoloader


Reference: https://github.com/laravel/laravel/blob/develop/composer.json




回答2:


You should use composer dump-autoload command. From the docs:

Once you have written your seeder, you may need to regenerate Composer's autoloader using the dump-autoload command:

composer dump-autoload

Reference here.



来源:https://stackoverflow.com/questions/27426139/laravel-5-how-can-i-add-seeder-class-to-autoload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!