modifyQueryUsing breaks ToggleColumn

in the app/Filament/Resources/FormResource.php file i set up the table:
public static function table(Table $table): Table
{
    return $table
        ->modifyQueryUsing(function (Builder $query) {
            $query->when(! auth()->user()->isAdmin(), function ($query) {
                $query->whereHas('users', function ($query) {
                    $query->where('users.id', auth()->id());
                });
                $query->orWhere('created_by_id', auth()->id());
            });
        })
        ->columns([
            Tables\Columns\ToggleColumn::make('is_active')
    ...

if the user is not admin, i want to show their created forms or the forms they are attached to.

the issue is that when i modify the query, if the user is admin, works just fine, but if the user is not admin, if the user toggles the is_active column, it toggles the last row being shown in the table!

https://filamentphp.com/docs/3.x/panels/resources/listing-records#customizing-the-table-eloquent-query

i think the issue is related to the
or
. why? because if i change the
orWhere
to a
where
, the toggle works fine, but then the query is not the query i want.
im doing something wrong or it's actually a bug?

update:
i also tried it this way. this way makes the toggles to not change
->query(function (Builder $query) {
    return static::getEloquentQuery()->when(! auth()->user()->isAdmin(), function ($query) {
        $query->whereHas('users', function ($query) {
            $query->where('users.id', auth()->id());
        });
        $query->orWhere('created_by_id', auth()->id());
    });
})
Was this page helpful?