filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.08k stars 2.94k forks source link

Adding a table to a custom page leads not working #2372

Closed vv-ac closed 2 years ago

vv-ac commented 2 years ago

Package

filament/tables

Package Version

v2.12.2

Laravel Version

v9.12.0

Livewire Version

v2.10.5

PHP Version

PHP 8.1.4

Bug description

When adding a table to a custom page with minimum options the following happens:

Typed property App\Filament\Resources\PostResource\Pages\ManagePost::$cachedTableFilters must not be accessed before initialization

Steps to reproduce

Using a custom page that holds multiple forms. Now we add a table in there. Using the following excerpt:

namespace App\Filament\Resources\PostResource\Pages;
use App\Filament\Resources\PostResource;
use Filament\Resources\Pages\Page;
use Illuminate\Database\Eloquent\Builder;
use Filament\Tables;

class ManagePost extends Page implements Tables\Contracts\HasTable
{
   use Tables\Concerns\InteractsWithTable;

    protected function getTableQuery(): Builder
    {
        return Postrequirement::query();
    }
}

In the respective blade the follwing is inserted:

{{ $this->table }}

Now refreshing the page leads to the mentioned error message above.

Relevant log output

No response

danharrin commented 2 years ago

Please check if #2410 fixes this.

vv-ac commented 2 years ago

Hi, thanks for coming up with a fix (in such a short time). How do I require a specific PR to be included? It's rather a branch to be included right? If so which is it?

Thank you!

danharrin commented 2 years ago

You can follow the Contributing guide in the README to set up a local version of the codebase, you can use the branch associated with that PR for testing.

I do believe I have fixed your issue though, so the PR is going to be merged. Let me know if that's not the case.

vv-ac commented 2 years ago

I just updated to v2.12.8 and still have the same issue, here is the entire code after removing most of the content (other forms, form content etc.) from it:

<?php

namespace App\Filament\Resources\AssessmentResource\Pages;

use App\Filament\Resources\AssessmentResource;
use Filament\Resources\Pages\Page;

use Illuminate\Database\Eloquent\Model;
use App\Models\Assessment;
use App\Models\AssessmentRequirement;

use Illuminate\Database\Eloquent\Builder;

use Carbon\Carbon;

use Closure;

use Filament\Tables;
// use Filament\Tables\Columns\TextColumn;

use Filament\Forms;

use Filament\Pages\Actions\ButtonAction;

class ManageAssessment extends Page implements Tables\Contracts\HasTable
{
    protected static string $view = 'filament.resources.assessment-resource.pages.manage-assessment';

    protected static string $resource = AssessmentResource::class;

    protected static ?string $model = Assessment::class;

    public $record;

    public function mount(Assessment $record)
    {
        $this->record = $record;

        $this->requirementsForm->fill([
            //
        ]);
    }

    protected function getForms(): array
    {
        return [
            'requirementsForm' => $this->makeForm()
                ->schema($this->getRequirementsFormSchema())
                ->model($this->record),
        ];
    }

     protected function getRequirementsFormSchema(): array
    {
         return [
             Grid::make([
                 'default' => '1',
             ])
             ->schema([
                 Placeholder::make('')
                     ->content(new HTMLString('blablabla.')),
             ]),
         ];
     }

    use Tables\Concerns\InteractsWithTable;

    protected function getTableQuery(): Builder
    {
        return AssessmentRequirement::query();
    }

}

It still returns

Typed property App\Filament\Resources\AssessmentResource\Pages\ManageAssessment::$cachedTableFilters must not be accessed before initialization
danharrin commented 2 years ago

It's not been released yet

vv-ac commented 2 years ago

Works!