FilamentF
Filament12mo ago
frame

Custom resource page $this->record null when searching/sorting

The table renders fine initially, but when trying to sort or search $this->record is null. Am I missing some trait or something? 🤔
Same question as this removed one ❓┊helpTable builder records are null after update

<?php

namespace App\Filament\Instructors\Resources\GroupResource\Pages;

use App\Filament\Instructors\Resources\GroupResource;
use App\Models\ExerciseResult;
use App\Models\Group;
use Filament\Actions\Concerns\InteractsWithRecord;
use Filament\Actions\Contracts\HasRecord;
use Filament\Resources\Pages\Page;
use Filament\Tables;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;

class SimpleResults extends Page implements HasRecord, HasTable
{
    use InteractsWithRecord;
    use InteractsWithTable;

    public function mount(string $record): void
    {
        $this->record = Group::where('uuid', $record)->firstOrFail();
    }

    protected static string $resource = GroupResource::class;

    protected static string $view = 'filament.instructors.resources.group-resource.pages.simple-results';

    public function getModel(): string
    {
        return Group::class;
    }

    public function table(Table $table)
    {
        return $table
            ->query(function () {
                dump($this->record); // null if searching/sorting

                return ExerciseResult::forGroup($this->record);
            })
            ->columns([
                Tables\Columns\TextColumn::make('created_at')
                    ->label('Created at')
                    ->sortable()
                    ->searchable(),
            ])
            ->actions([]);
    }
}
Solution
Actually did not work I just messed up. What really worked is setting additional public MyModel $myRecord; in the page and setting that on mount and using that instead of $this->record
Was this page helpful?