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.09k stars 2.83k forks source link

Does not filter correctly with multiple where in getEloquentQuery #8975

Closed mendizalea closed 9 months ago

mendizalea commented 11 months ago

Package

filament/filament

Package Version

3.0.71

Laravel Version

10.26.2

Livewire Version

3.0.6

PHP Version

8.2.11

Problem description

It does not filter correctly when you select, for example, status by any of the options or when the resource is started with the default filter.

Expected behavior

That filters correctly whether with the default or with any selected options.

Steps to reproduce

Once the Ticket resource is opened, it does not filter correctly through the default state filter. If you select any of the options in the filter it doesn't work either.

Reproduction repository

https://github.com/mendizalea/filament-query-bug/tree/master

Relevant log output

No response

github-actions[bot] commented 11 months ago

Hey @mendizalea! We're sorry to hear that you've hit this issue. 💛

However, it doesn't look like you've provided much information on how to replicate the issue. Please edit your original post with clear steps we need to take.

github-actions[bot] commented 11 months ago

Thank you for providing reproduction steps! Reopening the issue now.

zepfietje commented 11 months ago

Could you confirm if this is caused by https://github.com/filamentphp/filament/issues/8972, @mendizalea? Maybe by switching to native(false) on the select?

mendizalea commented 11 months ago

Could you confirm if this is caused by #8972, @mendizalea? Maybe by switching to native(false) on the select?

I couldn't tell you for sure if it is related, but I would say that is not related. I just tried with native(false) and same problem.

zepfietje commented 11 months ago

Alright, will leave this issue open then.

mendizalea commented 11 months ago

Alright, will leave this issue open then.

I have detected a second problem related to this. When I go to edit or view a table record it always opens the same record.

danharrin commented 9 months ago

The orWhere() is interfering with further constraints applied by the filters etc:

public static function getEloquentQuery(): Builder
    {
        return parent::getEloquentQuery()->withoutGlobalScopes([SoftDeletingScope::class])
            ->where(fn ($query) => $query->whereBelongsTo(auth()->user(), 'ownedBy')
            ->orWhereBelongsTo(auth()->user(), 'requestedBy'));
    }

Wrapping both in a nested where() should fix all issues