Searchable column with scoped model

I've got a table on a custom page which uses a model with a scope for its query.
This is the scope:
public function scopeCalculatedClassFrequencies(Builder $query, string|null $name = null): void
    {
        $query->select(
            $this->getTable() . '.id',
            DB::raw('"' . __('Zügigkeiten') . '" as name'),
            DB::raw('LEFT(j.titel, 4) as year'),
            DB::raw('SUM(cf.zuegigkeit) AS calculated_value'),
            $this->getTable() . '..number AS expected_value',
        )
            ->where('reference', 'class-frequencies')
            ->join(app(Year::class)->getTable() . ' as j', DB::raw('LEFT(j.titel, 4)'), '=',  $this->getTable() . '.year')
            ->join(app(ClassFrequency::class)->getTable() . ' as cf', 'cf.jahrgang', '=', 'j.id')
            ->groupBy(DB::raw('LEFT(j.titel, 4)'))
            ->orderBy('year')
    }

The table uses this scope as the query and a searchable name column. Because of the scope I use a callback function to add the search condition to the query:
$table->query(ImportExpectation::CalculatedClassFrequencies())
->columns([
                TextColumn::make('name')
                    ->searchable(isGlobal: false, isIndividual: true, query: function(Builder $query, string $search) {
                        $query->having('name', 'like', '%' . $search . '%');
                }),

Unfortunately the search doesn't apply to the data. The table shows that a filter is active with the search string, but still all data is shown. Any idea what I'm doing wrong?
Was this page helpful?