F
Filament7mo ago
Kurja

using an accessor as the attribute in a selectFilter in table

Hi, is it possible to use accessor as filters in tables? I'm trying to use an accessor in a SelectFilter and I'm getting the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'publish_status' in 'where clause'
My code is the following $table->filters([ SelectFilter::make('status') ->label('Publish status') ->options([ 'published' => 'published', 'scheduled' => 'scheduled', 'draft' => 'draft', ]) ->attribute('publish_status'), ]) And the accesor in the model is the following public function publishStatus(): Attribute { return Attribute::make( get: function() { if ($this->published_at) { return 'published'; } if ($this->scheduled_at) { return 'scheduled'; } return 'draft'; }, ); } Any help appreciated, thanks in advance
3 Replies
Dennis Koch
Dennis Koch7mo ago
Hi, is it possible to use accessor as filters in tables?
Short answer: No Long answer: Search and filters are performed on the database level, therefore it needs a database column.
Kurja
Kurja7mo ago
thanks for the answer. Is there a way to use the query method with the options of a select filter? If not, I will probably have to split each field into a different filter
Dennis Koch
Dennis Koch7mo ago
You mean ->query()? Yes you should be able to overwrite the default behaviour