Wednesday, March 7, 2018

Laravel programatically calling artisan command from web.php in production - development

Laravel programatically calling artisan command from web.php in production

I have below route:

Route::get('/beneficiaries/seed', function () {
    echo "<p>Database seeding started...</p>";
    $exitCode = Artisan::call('db:seed');
    echo "<p>Database seeding completed.</p>";
});

In my local environment, when I visit ‘/beneficiaries/seed’, it seeds the database. But if I do the same in production, it doesn’t. I just copied the seeder classes and route file.

DatabaseSeeder:

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        $this->call(BeneficiariesTableSeeder::class);
    }
}

BeneficiariesTableSeeder:

class BeneficiariesTableSeeder extends Seeder
{
    public function run()
    {
        //seeding logic...
    }
}

Why my production Artisan command doesn’t get executed? (I haven’t used database transaction. Even w/o it, local db gets seeded since there is no err is raised.)



from Laravel Questions and Answers https://laravelquestions.com/php/laravel-programatically-calling-artisan-command-from-web-php-in-production/
via Lzo Media

No comments:

Post a Comment