Skip to content

Conversation

neellii
Copy link

@neellii neellii commented Oct 16, 2025

refs: #203

Copy link
Contributor

@Copilot Copilot AI left a 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);
Copy link

Copilot AI Oct 16, 2025

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.

@neellii neellii assigned neellii and unassigned DenTray Oct 16, 2025
protected function getRelationType(string $relation, string $type): string
{
if (in_array($type, self::PLURAL_NUMBER_REQUIRED)) {
return "Collection|$relation";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "Collection|$relation";
return "Collection<{$relation}>";

Comment on lines +211 to +213
$relation = class_basename($relation);

$result[$this->getRelationName($relation, $type)] = $this->getRelationType($relation, $type);
Copy link
Collaborator

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)

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