Remove controller file using PHP artisan

<?php

/**
 * Just Copy and paste the below code into your routes/console.php file. 
 * Now write command: php artisan remove:controller ControllarName 
 */

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');

Leave a Reply

Your email address will not be published. Required fields are marked *