Don't override model
Closed this issue · 12 comments
Would be cool to be able to generate crud for exiting models e.g. if the model file exists, just 'skip' generating
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.
well, how do I then create CRUD for existing Models ?
Aha, I got your point now. So what is currently happening:
Current behavior:
- let say we have an existing Invoice model.
- We run the make:crud command for that model.
- The package will ask if we want to create CRUD scaffolds for an existing model.
- 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?
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.
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.
Aha, got it.
Only one small thing: It create a new migration file