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
18.69k stars 2.91k forks source link

Eagerload query get replaced by Filament #5489

Closed rahmanramsi closed 1 year ago

rahmanramsi commented 1 year ago

Package

filament/tables

Package Version

v2.16.62

Laravel Version

v9.48.0

Livewire Version

v2.11.0

PHP Version

PHP 8.1.14

Problem description

When manually eager load a relation

    protected function getTableQuery(): Builder
    {
        return Post::query()
            ->with([
                'author' => fn ($query) => $query->withTrashed()
            ]);
    }

And then show it on column

Tables\Columns\TextColumn::make('author.name')

A relation that manually eager load before get replaced by Filament.

Author relation with trashed get retrieved image

Expected behavior

Author relation with trashed get retrieved

image

Steps to reproduce

  1. Clone repo
  2. Migrate everything
  3. Serve laravel

Reproduction repository

https://github.com/rahmanramsi/filament-eagerload

Relevant log output

No response

danharrin commented 1 year ago

Thanks for the issue! But I don't think it's something "wrong" with Filament, because this is how Eloquent behaves when you try to eagle-load something twice. Not really something we can fix in our own code.

However, I understand why withTrashed() would be useful. So I propose that you add a scopeRelationshipUsing() method to the Column which could enable this behaviour by accepting a $query callback. A PR would be great!