How to delete a model using php artisan?

前端 未结 6 1550
Happy的楠姐
Happy的楠姐 2021-02-02 06:57

Is there a command to safely delete a model in Laravel 5? To create a model we use

php artisan make:model modelname

And that will create a mode

6条回答
  •  不知归路
    2021-02-02 07:26

    Here is what I've created for my project to remove controller and model

    app/Console/Commands/RemoveController.php

    argument('name').'.php';
            $controllerPath = base_path('app/Http/Controllers/').$controllerName;
            if(file_exists($controllerPath)){
                unlink($controllerPath);
                $this->line('Controller removed successfully.');
            }else{
                $this->line('No controller found.');
            }
        }
    }
    

    app/Console/Commands/RemoveModel.php

    argument('name').'.php';
            $modelPath = base_path('app/').$modelName;
            if(file_exists($modelPath)){
                unlink($modelPath);
                $this->line('Model removed successfully.');
            }else{
                $this->line('No controller found.');
            }
        }
    }
    

    I Hope this helps someone

提交回复
热议问题