Skip to content

Instantly share code, notes, and snippets.

@asifulmamun
Forked from miftahafina/console.php
Created August 16, 2023 16:08
Show Gist options
  • Save asifulmamun/874f192757262fd78305771a4371700a to your computer and use it in GitHub Desktop.
Save asifulmamun/874f192757262fd78305771a4371700a to your computer and use it in GitHub Desktop.
Remove laravel controller with artisan command
<?php
/**
* Copy and paste the code below into your routes/console.php file.
* You can add more command such as 'remove:model', 'remove:middleware', etc if you want,
* just modify the $file_location variable.
*/
Artisan::command('remove:controller {name : Name of the controller}', function ($name) {
// File location
$file_location = base_path() . '/app/Http/Controllers/' . $name . '.php';
// Check if exist
if (file_exists($file_location)) {
exec('rm ' . $file_location);
$this->info($name.' has been deleted!');
} else {
$this->error('Cannot delete ' . $name . ', file not found.');
}
})->describe('Remove spesific controller');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment