Skip to content

[12.x] Allow creating additional components when model already exists #56513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 3, 2025

Conversation

mechelon
Copy link
Contributor

@mechelon mechelon commented Aug 1, 2025

When running make:model Conference and forgetting flags like -mf, the command fails if the model already exists. This forces developers to either manually create missing components manually or use the --force flag which will delete existing implementations inside the model (or delete the model and start over).

Suggestion

Instead of failing, prompt the user to create additional components using the same interactive multiselect interface available when running make:model without parameters.

Example

Before

✨ php artisan make:model Conference

   ERROR  Model already exists.

After

✨ php artisan make:model Conference

   ERROR  Model already exists.

 ┌ Do you want to generate additional components for Model Conference? ┐
 │ Yes                                                                 │
 └─────────────────────────────────────────────────────────────────────┘

 ┌ Would you like any of the following? ────────────────────────┐
 │ › ◻ Database Seeder                                        ┃ │
 │   ◻ Factory                                                │ │
 │   ◻ Form Requests                                          │ │
 │   ◻ Migration                                              │ │
 │   ◻ Policy                                                 │ │
 └──────────────────────────────────────────────────────────────┘

I've also added a test to the best of my knowledge.
I think this improves the DX by allowing to add forgotten components without starting over. (I run into this on a regular basis. 😅)

mechelon and others added 3 commits July 31, 2025 13:21
When running `make:model` for an existing model, prompt the
user to create additional components (migration, factory, etc.)
instead of failing with an error.
@taylorotwell taylorotwell merged commit 3a58c24 into laravel:12.x Aug 3, 2025
59 of 60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants