Laravel – Call database seeder class from controller

Sometimes you may need to see the results of a specific seeder class on a web page instead of a terminal.

Thus instead of calling the seeder class via terminal:

Call the class from within a controller, and here is the way I used to achieve that:

First, inside your seeder class add the namespace you want, I do that by writing the folders as a namespace.



Very Important to know that this affects the seeder class, now if you want to use DB Facade earlier you got it by default, but now you must add it to your seeder manually, the same for Log Facade and other Facades…


If you are going to use the same seeder in the terminal after doing the above changes you will get this error:
ReflectionException : Class StreetSeeder does not exist
And this happens because now Laravel does not recognize the seeder class because of the new namespace you added.

To Fix the error

Thanks for reading


Hello, I'm Mohammad Daka, software engineer who love coding. In my spare time I blogs about JavaScript,PHP, Chrome Extensions, helpful resources and tools, I'm also working on my own projects. Don't hesitate to contact me at my twitter account: @mohammad_daka :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *