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');
Customizable Disclaimer Section: Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Leave a Reply

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