-
Notifications
You must be signed in to change notification settings - Fork 3
[203]: add model relations property annotations #208
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds model relations property annotations to Laravel models by generating @property
annotations for relationships. The implementation adds support for both single and collection-based relationships with appropriate type hints.
- Adds
@property
annotations for model relationships in generated models - Imports
Illuminate\Database\Eloquent\Collection
when collection-type relations are present - Generates proper type hints for singular (
Model|null
) and plural (Collection|Model
) relationships
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
stubs/model.blade.php | Adds conditional import for Collection class when collection-type relations exist |
src/Generators/ModelGenerator.php | Implements logic to generate relation annotations and determine Collection import necessity |
tests/fixtures/ModelGeneratorTest/*.php | Test fixtures showing expected output with relation property annotations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
foreach ($relations as $relation) { | ||
$relation = class_basename($relation); | ||
|
||
$result[$this->getRelationName($relation, $type)] = $this->getRelationType($relation, $type); |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method getRelationName()
is being called but is not defined in this class. This will cause a fatal error when the code is executed.
Copilot uses AI. Check for mistakes.
protected function getRelationType(string $relation, string $type): string | ||
{ | ||
if (in_array($type, self::PLURAL_NUMBER_REQUIRED)) { | ||
return "Collection|$relation"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "Collection|$relation"; | |
return "Collection<{$relation}>"; |
$relation = class_basename($relation); | ||
|
||
$result[$this->getRelationName($relation, $type)] = $this->getRelationType($relation, $type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's try to refactor it to prevent code duplication (the same logic already exists in the prepareRelations
)
refs: #203