Dmitry
Dmitry

Reputation: 7563

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?

Upvotes: 7

Views: 9233

Answers (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.

Upvotes: 0

Eduardo Trujillo
Eduardo Trujillo

Reputation: 531

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

Upvotes: 16

Related Questions