#Route query string values don't persist with pagination in Table

10 messages · Page 1 of 1 (latest)

barren solstice
#

Hello , good evening i need help here is my code :

public static function table(Table $table): Table
    {
        return $table
            ->query(
                Transaction::query()
                    ->where('user_id', request()->get('record')))
            ->columns([
                //
            ])
            ->filters([
                //
            ])
            ->persistFiltersInSession()
            ->persistSortInSession()
            ->actions([
                Tables\Actions\EditAction::make(),
                Tables\Actions\DeleteAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

how to make the table not forget about request()->get('record')

thanks

tender jettyBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

smoky oasis
#

Is this inside a resouece view page or a custom resource page?

You should be able to do something like $this->getRecord()

barren solstice
#

it is inside a resource class BeneficiaryTransactionResource extends Resource

smoky oasis
#

If record is a custom query parameter you set on the get request to your BeneficiaryTransactionResource list page you can do this:

One way you could achieve this is by making a ListBeneficiaryTransactionResource class (should have this file already as filament auto created them if you use the resource helper)

Then inside that list class add a url property (livewire auto sets this based on the url query param:

#[Url]
public $record = ''; 

Then you can create a function inside the same class that modifies the table query for the resource like:

protected function getTableQuery(): Builder
{
dd($this->record);
return parent::getTableQuery()
->where('user_id', $this->record)
}

#

Also remember to import use Livewire\Attributes\Url;

barren solstice
#

<?php

namespace App\Filament\Manager\Resources;

use App\Enum\TransactionClassification;
use App\Filament\Manager\Resources\BeneficiaryTransactionResource\Pages;
use App\Filament\Manager\Resources\BeneficiaryTransactionResource\RelationManagers;
use App\Filament\SharedForm\TransactionForm;
use App\Models\BeneficiaryTransaction;
use App\Models\Transaction;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\URL;

class BeneficiaryTransactionResource extends Resource
{
    protected static ?string $model = Transaction::class;

    #[URL]
    public ?string $record;

    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                //
            ]);
    }

    public static function shouldRegisterNavigation(): bool
    {
        return false;
    }

    public static function table(Table $table): Table
    {
        return $table
            ->defaultSort('created_at', 'desc')
            ->columns(TransactionForm::tableBeneficiarySchema())
            ->persistFiltersInSession()
            ->persistSortInSession();

    }


    protected function getTableQuery(): Builder
    {
        return parent::getTableQuery()
            ->where('user_id', $this->record);
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ManageBeneficiaryTransactions::route('/'),
        ];
    }
}


this is what i have but still doest work , getTableQuery is completely ignored

smoky oasis
#

You need to place these in the ListBeneficiaryTransaction class. Sorry if i wasnt clear in the last message as you need a livewire component to manage your custom state

barren solstice
#

thanks this works,


class ManageBeneficiaryTransactions extends ManageRecords
{
    #[URL]
    public ?string $record;
    protected static string $resource = BeneficiaryTransactionResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Actions\CreateAction::make(),
        ];
    }

    protected function getTableQuery(): Builder
    {
        return parent::getTableQuery()
            ->where('user_id', $this->record);
    }

}

after i added in my ManageRecords

smoky oasis
#

Good to hear happy to help 🙂 🙌