Power-Components / livewire-powergrid

⚡ PowerGrid generates modern, powerful and easy-to-customize data tables using Laravel Livewire.
https://livewire-powergrid.com
MIT License
1.46k stars 215 forks source link

Attempt to read property "layout" on array #1357

Closed indovsky closed 7 months ago

indovsky commented 7 months ago

Have you searched through other issues to see if your problem is already reported or has been fixed?

Yes, I did not find it.

Did you read the documentation?

Yes, I did not find it.

Have you tried to publish the views?

Yes - I didn't work.

Is there an error in the console?

powergrid

PHP Version

8.2

PowerGrid

5.3

Laravel

10.42

Livewire

3.3

Alpine JS

3.4.2

Theme

Tailwind 3.x with tailwind/forms

Describe the bug.

Fresh instance of laravel with powergrid. After creating a table and view with a table component I get an error "Attempt to read property "layout" on array". After publishing powergrid views and @dd($theme->layout) in /resources/views/vendor/livewire-powergrid/components/frameworks/tailwind/table-base.blade.php i can see $theme->layout returning array instead object.

Have I done something wrong or is this a bug?

To Reproduce...

Fresh installation

Extra information

No response

dansysanalyst commented 7 months ago

Hi @indovsky,

I could not replicate your issue.

I have just created two PowerGrid components with Eloquent and one Collection data source, both using Tailwind.

indovsky commented 7 months ago

Hi @indovsky,

I could not replicate your issue.

I have just created two PowerGrid components with Eloquent and one Collection data source, both using Tailwind.

  • Are you using the default theme, or have you created your own theme?
  • Could you please share your component's code (e.g., app/Livewire/YourTable.php)?

Problem solved by updating laravel and livewire to newest version. My bad 😅

akulmehta commented 7 months ago

I am facing this same issue - when upgrading from 4.x to 5.x. The issue is mainly the $theme appears to be an array as can be seen with the dd: image

Upgrading Livewire and Laravel didn't solve it for me.

This is probably not table specific as it is happening on all tables. Any suggestions?

akulmehta commented 7 months ago

Update: The issue may be in the following code:

// src/PowerGridComponent.php

    private function getTheme(): array
    {
        $class = $this->template() ?? powerGridTheme();

        return Cache::rememberForever('powerGridTheme_' . $class, function () use ($class) {
            /** @var ThemeBase $themeBase */
            $themeBase = PowerGrid::theme($class);

            return convertObjectsToArray((array) $themeBase->apply());
        });
    }

which returns an array to the renderView method

// src/PowerGridComponent.php

    private function renderView(mixed $data): Application|Factory|View
    {
        $theme = $this->getTheme();

        return view($theme['layout']['table'], [
            'data'  => $data,
            'theme' => $this->getTheme(),
            'table' => 'livewire-powergrid::components.table',
        ]);
    }
indovsky commented 7 months ago

I am facing this same issue - when upgrading from 4.x to 5.x. The issue is mainly the $theme appears to be an array as can be seen with the dd: image

Upgrading Livewire and Laravel didn't solve it for me.

This is probably not table specific as it is happening on all tables. Any suggestions?

Hi, after updating Laravel and Livewire, remove Powergrid from Composer. If you published Powergrid views, be sure to delete them and then reinstall Powergrid

luanfreitasdev commented 7 months ago

Hello @akulmehta, did @indovsky suggestion work?

akulmehta commented 7 months ago

@luanfreitasdev no it didn't unfortunately. I updated everything and tried clearing all caches and views. I even tried installing PowerGrid v. 5.3.3 or 5.3.5 and even that didn't work.

I am wondering if this occurrs only on legacy tables which are upgraded from 3.x to 4.x to 5.x.

luanfreitasdev commented 7 months ago

I believe you should completely remove published views (resources/views/vendor/...) and clear the cache on a refresh (optimize:clear).

dansysanalyst commented 7 months ago

@akulmehta Please create a new issue if the solutions provided here (and in the documentation) do not help.

It's not comfortable for other users to receive updates on an issue that it was already solved.

akulmehta commented 7 months ago

I know I shouldn't comment here but I solved my issue and didn't want to create a separate issue so I will post my solution here. For some reason publishing the views were not overwriting the previously published views I had. I manually deleted the resources/views/vendor/livewire-powergrid folder and published the views again and it worked. Thank you for your help.

luanfreitasdev commented 7 months ago

Thank you @akulmehta