Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Laravel 5 seeder programmatically instead of from CLI

Tags:

Is there a way to run the Laravel 5 seeder from within PHP rather than from the command line. The hosting I am using doesn't allow me to use the command line. Just to confirm I want to do the equivalent of this but in my app code:

php artisan db:seed 
like image 731
geoffs3310 Avatar asked Mar 01 '15 22:03

geoffs3310


People also ask

Which command to run seeding in Laravel?

Laravel Seeding Creating a Seeder To create seeders, you may use the make:seeder Artisan command. All seeders generated will be placed in the database/seeds directory. Generated seeders will contain one method: run . You may insert data into your database in this method.

How do I run a seeder from a controller?

@nhayder you can just new up the seeder inside your controller and get any public properties or run the run() method. $seeder = new \Database\Seeds\WantedSeeder(); $seeder->run();


1 Answers

You can use the following method:

Artisan::call('db:seed'); 

To get the output of the last run command, you can use:

Artisan::output(); 
like image 90
Bogdan Avatar answered Oct 18 '22 17:10

Bogdan