Skip to content

Conversation

@chetanupare
Copy link
Contributor

What stubs were updated

  • Model generation output (PHPDoc-enabled mode):
    • Models generated when blueprint.generate_phpdocs=true now include a trait-level PHPDoc @use annotation for HasFactory.
  • No stub template file was changed (e.g. stubs/model.class.stub stayed the same).
    • The change is implemented in the generator: src/Generators/ModelGenerator.php (overrides trait rendering for models).
  • Test fixtures updated to reflect the new expected output:
    • tests/fixtures/models/readme-example-phpdoc.php
    • tests/fixtures/models/relationships-phpdoc.php
    • tests/fixtures/models/soft-deletes-phpdoc.php
    • tests/fixtures/models/disable-auto-columns-phpdoc.php
    • tests/fixtures/models/foreign-key-shorthand-phpdoc.php

Example before / after

Before (generated model, PHPDoc enabled):

class Post extends Model
{
    use HasFactory;
}

After (generated model, PHPDoc enabled):

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

SoftDeletes stays a real trait (no regression):

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

How this improves static analysis (PHPStan / IDE type inference)

  • Eliminates missing/unclear generic warnings for HasFactory by explicitly declaring the factory type via @use HasFactory<...>.
  • Improves IDE autocomplete and navigation:
    • IDEs can more reliably infer the associated Factory class for a model and offer better completion for factory-related calls.
  • Keeps runtime behavior unchanged:
    • This is purely an annotation enhancement; traits like SoftDeletes remain actual use SoftDeletes; statements (not moved into PHPDoc).

@jasonmccreary jasonmccreary merged commit c3fa824 into laravel-shift:master Jan 27, 2026
19 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