Filter table with metadata column

Hi everyone, I have a table where the displayed information is from the primary table + joined column from the metadata table. My Select Filters work for the columns on the main table, but when I run my select filter on the joined metadata table, I get an error stating the column 'status' cannot be found on the table. Attribute on the primary table model protected function status(): Attribute { return Attribute::make( get: fn () => $this->attributes()->where('key', 'status')->first()->value ?? null, set: fn ($value) => $this->attributes()->updateOrCreate(['key' => 'status'], ['value' => $value]) ); } Column on the Primary Table SelectColumn::make('status') ->options(ResourceOption::where('resource', 'renewals')->get()->keyBy('id')->map(fn ($item) => $item->name)->toArray()) ->placeholder(''), Select Filter on the Primary Table for the Metadata column SelectFilter::make('status') ->options( ResourceOption::where('resource', 'renewals') ->where('type', 'status') ->get() ->keyBy('id') ->map(fn ($item) => $item->name) ->toArray() ) ->multiple(),
3 Replies
Patrick Boivin
Patrick Boivin15mo ago
How are you doing the join with the metadata table?
blackdog308
blackdog308OP15mo ago
'public function attributes(): MorphMany { return $this->morphMany(Metadata::class, 'attributable'); } }'
Patrick Boivin
Patrick Boivin15mo ago
status is not a column on the Eloquent query, that's why it doesn't work as a filter
Want results from more Discord servers?
Add your server