Last active
March 31, 2024 15:49
-
-
Save miftahafina/292deed1265f2e404e5cd2229ef3ed78 to your computer and use it in GitHub Desktop.
Remove laravel controller with artisan command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
Tambah hapus model om sekalian 😍
Tambah hapus model om sekalian 😍
Bisa, cukup ganti pathnya aja di variabel $file_location
Hi. What should I change $file_location
to?
@Luckiees you have to change the command('remove:controller and path /app/Http/Controllers/ if you want to remove something else than a controller. It's a good example how to create a command for the console but dangerous because as written before it removes your code from the disk and don't reflect on routes and other usage of your controller.
@zalaudekr Thank you so much😄
Good
@miftahafina
miftahafina Thank you.
@miftahafina could it be possible this way to remove the entire controller folder?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wkwk sangar