简体   繁体   中英

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

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?

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM