Brainmaniac
Brainmaniac

Reputation: 2556

Laravel delete model, controller and migration in single artisan command?

As the title says; is there a way to delete/revert/rollback the creation of the files created when running php artisan make:model MyModel -mcr?

Something like:

php artisan destroy:model MyModel

.. and it "cascade" delete all related files?

Upvotes: 5

Views: 9846

Answers (2)

DAVID AJAYI
DAVID AJAYI

Reputation: 2154

Just do it manually, no command as of this writing

  1. Delete the model first (if you don't) need the model any longer
  2. Delete the migration from ...database/migrations folder
  3. If you have already migrated i.e if you have already run php artisan migrate, log into your phpmyadmin or SQL(whichever the case is) and in your database, delete the table created by the migration
  4. Still within your database, in the migrations folder, locate the row with that migration file name and delete the row.

Works for me, hope it helps!

Upvotes: 8

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

When you run

php artisan make:model --help

command you must be see

Usage:
  make:model [options] [--] <name>

Arguments:
  name                  The name of the class

Options:
  -a, --all             Generate a migration, factory, and resource controller for the model
  -c, --controller      Create a new controller for the model
  -f, --factory         Create a new factory for the model
      --force           Create the class even if the model already exists
  -m, --migration       Create a new migration file for the model
  -p, --pivot           Indicates if the generated model should be a custom intermediate table model
  -r, --resource        Indicates if the generated controller should be a resource controller
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose outp
ut and 3 for debug

That mean dy default it is not poosible. You must be make your own artisan command for it. Also if you want know about artisan command options and arguments use

php artisan command_name --help

Upvotes: 4

Related Questions