Skip to content
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

[11.x] Feat: factory generic in model #52855

Open
wants to merge 4 commits into
base: 11.x
Choose a base branch
from

Conversation

MrPunyapal
Copy link
Contributor

Based on this comment by @taylorotwell, I have adjusted the make:model command to include a factory doc-block.

For example, if I run the following command:

php artisan make:model Post

I will get a file with the code below, as it was before:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasFactory;
}

However, if I run the following command:

php artisan make:model Comment -f

or any other command that generates a factory along with it, the resulting file will contain the code below:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    /** @use HasFactory<\Database\Factories\CommentFactory> */
    use HasFactory;
}

@MrPunyapal MrPunyapal changed the title Feat: factory generic in model [11.x] Feat: factory generic in model Sep 19, 2024
@Jubeki
Copy link
Contributor

Jubeki commented Sep 20, 2024

Just as an idea: Could you not also replace the HasFactory use with an empty string if the flag --factory is not set?

(Change in behaviour, but acceptable in my opinion)

@MrPunyapal
Copy link
Contributor Author

@Jubeki
I thought for the same

But yeah it's a change in behaviour!

I would like to see @taylorotwell's thoughts on the same.

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