nafiesl/SimpleCrudGenerator

Don't override model

Closed this issue · 12 comments

rabol commented

Would be cool to be able to generate crud for exiting models e.g. if the model file exists, just 'skip' generating

Hello @rabol, I think this is related to #24.

Currently, we have a confirmation question to generate CRUD files for the existing model.

image

rabol commented

Yes, I have seen, but if you say, no, then nothing is created

vagrant@homestead:~/code/test$ artisan make:crud User

 Model file exists, are you sure to generate CRUD files? (yes/no) [no]:
 > no

User model already exists.

Correct @rabol, that is expected.

Do you have any suggestion if we answering "no", @rabol?

rabol commented

well, how do I then create CRUD for existing Models ?

Aha, I got your point now. So what is currently happening:

Current behavior:

  1. let say we have an existing Invoice model.
  2. We run the make:crud command for that model.
  3. The package will ask if we want to create CRUD scaffolds for an existing model.
  4. If we answer "yes", the package will replace all of the existing Invoice model content.

Expected behavior:
4. After we answer "yes", just create the scaffolds, don't touch the existing Invoice model class.

Correct, @rabol?

rabol commented

yes, only 'override' existing files if --force is specified on the command line, like many other artisan commands, please

Gotcha, nice catch @rabol, thanks for reporting this issue. I will work on the fix.

@rabol, FYI, this is a draft PR for fixing the class overrides issue #35.

rabol commented

I just installed the new version 2.2.1 - still the same behaviour

php artisan make:crud Test

Crud is generated

2nd time

php artisan make:crud Test

It ask, and if I say No, nothing happens

Have a look at the CrudMake.php

in the handle() method

 if ($this->modelExists()) {
            $confirm = $this->confirm('Model file exists, are you sure to generate CRUD files?');
            if (!$confirm) {
                $this->error("{$this->modelNames['model_name']} model already exists.");
                return;
            }
        }

it will simply return if you say No

@rabol it's still expected. Try to answer "yes", it will create crud files without overriding your existing model.

rabol commented

Aha, got it.

Only one small thing: It create a new migration file

Only one small thing: It create a new migration file

@rabol regarding this one, I can make another PR for asking "Do you need to create a migration file for the existing model? (yes/no)".

Maybe for another release. 👍