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.26k stars 631 forks source link

[Reusing Layouts][BUG] Illegal offset type in isset or empty #2665

Open moskoweb opened 12 months ago

moskoweb commented 12 months ago

Describe the bug After updating a project from version 13 to 14, all editing screens simply stopped working, with the error "Illegal offset type in isset or empty", from what I understand, it seems that the model defined in the query is not passing for layout components.

I created a components Reusing Layouts, and when using it on a page, it seems that it doesn't receive the query values ​​from the main PageScreen.

To Reproduce Steps to reproduce the behavior:

  1. Create Reusing Layouts
  2. Include in fuction layout() in page Screen
  3. Access in browser.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots

Captura de Tela 2023-07-10 às 10 54 41 Captura de Tela 2023-07-10 às 10 55 09

Desktop (please complete the following information):

Server (please complete the following information):

moskoweb commented 12 months ago

From the new tests I did, it seems that the problem is using Layout::block and Layout::rows inside the component to be reused, before the update it worked, and now it seems that it is no longer allowed.

moskoweb commented 12 months ago

Getting it working again, but I don't think that's the best way to handle this problem.

I noticed that when creating the new element and calling the fields function, it returns an array, and when calling the index 0, it solves the problem. It seems that when calling the Component that the children are not just form fields, this error occurs.

(new FormTrackingLayout())->fields()[0],

However, this way, the Query from Screen is not passed on to the component.

Impeck commented 11 months ago

Had a similar problem after upgrading from 14.4.0 to 14.6.0

tabuna commented 11 months ago

Hi there. I wanted to let you know that I have been working on reproducing the problem you reported, but unfortunately, I haven't been successful in encountering the issue.

In my attempt to recreate the problem, I followed the instructions https://orchid.software/en/docs/rows/#reusing-layouts and implemented the code:

public function layout(): iterable
{
    return [
        new AddressLayout('order.shipping_address', 'Shipping Address'),
        new AddressLayout('order.invoice_address', 'Invoice Address'),
    ];
}

I executed the code and found no errors. I also attempted using the code wrapped in a group:

public function layout(): iterable
{
    return [
        Layout::block([
            new AddressLayout('order.shipping_address', 'Shipping Address'),
            new AddressLayout('order.invoice_address', 'Invoice Address'),
        ]),
    ];
}

Even after trying this alternative option, I encountered no errors or issues.

Therefore, it would be extremely helpful if you could provide additional information so that I can better understand the problem and assist you in resolving it. Please let me know if there's anything else you'd like me to try, or if you have any other suggestions.

Impeck commented 11 months ago

this design may have worked on earlier versions

public function layout(): array
{
    return [

        Layout::modal('exampleModal', [
            Layout::rows([]),
        ]),
        Layout::rows([
            Input::make('zero')
                 ->type('text')
                 ->title('Zero:')
         ]), 
        $this->layoutAnother(),
    ];
}

public function layoutAnother(): array
{
    $logic = true;

    $row =  Layout::rows([
        Input::make('one')
            ->type('text')
            ->title('One:')
    ]);

    if($logic){
        $row =  Layout::rows([
            Input::make('another')
                ->type('text')
                ->title('Another:')
        ]);
    }

    return [
        $row,
         Layout::rows([
            Input::make('two')
                 ->type('text')
                 ->title('Two:')
         ]),
    ];
}