orchidsoftware / platform

Orchid is a @laravel package that allows for rapid application development of back-office applications, admin/user panels, and dashboards.
https://orchid.software
MIT License
4.45k stars 655 forks source link

Undefined public property while inherit a Screen class #2879

Closed DocLM closed 2 months ago

DocLM commented 3 months ago

Describe the bug Public properties inherited by a Screen class are not filled with their value if a matching item is found in query method results.

This potentially break inherited logic from the parent class.

To Reproduce Steps to reproduce the behavior:

  1. Create a class Parent that extends Screen with a public property named $a;
  2. Define a query method that return an item to assign a value to $a;
  3. Create a Child class that extends Parent and access $a property.

Expected behavior Public properties that have a matching an item from query method should be setted even if they are inherited from the parent class.

Examples Parent.php

<?php

namespace App\Orchid\Screens\Example;

use Orchid\Screen\Screen;

class Parent extends Screen {
    public ?string $a = null;

    /**
     * Query data.
     *
     * @return array
     */
    public function query(): array
    {
        return [
            'a' => 'Example'
        ];
    }
}

Child.php

<?php

namespace App\Orchid\Screens\Example;

class Child extends Parent {
    public ?string $b = null;

    /**
     * Query data.
     *
     * @return array
     */
    public function query(): array
    {
        return array_merge(parent::query(), ['b' => 'Another property']);
    }
}

Accessing $b from child class have a defined value while $a is always null.

Server: