orchidsoftware / orchidsoftware/platform

`getContent()` returns Array instead of Collection or Model when eager loading relations

Open
#2,876 1 comment 0 reactions 1 assignee View on GitHub

@tabuna is already working on this.

Since Aug 15, 2024.

Experience
Dominant language
PHP
Stars
4.8k
Forks
663
Avg merge
1d 9h
Merged PRs (30d)
7

Description

Describe the bug
When a relation is eager-loaded, the getContent() method from the Orchid\Screen\AsSource trait returns an array instead of a collection or model.

To Reproduce
Steps to reproduce the behavior:

  1. Eager load a relation (in either the Resource class or the Model class).
  2. In Tinker, call YourModel::first()->getContent('relationName').

Expected behavior
The getContent() method should return a Collection or Model for consistency, especially when using it in a cell component with usingComponent().

Is there a specific reason for prioritizing an array return?

public function getContent(string $field)
{
    return Arr::get($this->toArray(), $field) // Try to get the field value from the object's array representation.
        ?? Arr::get($this->getRelations(), $field) // Try to get the field value from the object's relations.
        ?? $this->getAttribute($field);  // Try to get the field value from the object's attributes.
}

Server (please complete the following information):

  • Platform Version: 14.25.3
  • Laravel Version: 11.2.0
  • PHP Version: 8.3.10
  • Database: MariaDB
  • Database Version: 10.4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.