We are using Laravel artisan commands in localhost for create some laravel resources like creating controllers, models, middleware, jobs, etc.
But on serve, we have some restrictions so we are unable to use command line so we are unable to use artisan features so for this we can use laravel artisan helper call and call artisan command in our code like in web.php or in controllers easily.
let see how to call artisan command in laravel codes
// Clear cache
Route::get('/clear', function() { Artisan::call('cache:clear'); Artisan::call('clear-compiled'); Artisan::call('config:clear'); Artisan::call('config:cache'); Artisan::call('view:clear'); return "Cleared!"; });
// Migrate db
// Migrate db Route::get('/migrate', function() { Artisan::call('migrate'); return "Migrated!"; });
// Seed db
// Seed db Route::get('/seed', function() { set_time_limit(3600); Artisan::call('db:seed'); echo 'Seeded'; });