© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago
Nick

How-to create table filter from model accessor

Hello, I have an app that uses Laravel batches and I have a field on my "batched" model to track the batch and provide a status based on Laravel's built-in batch methods:

protected function batchStatus(): Attribute
    {
        return Attribute::make(
            get: function (mixed $value, array $attributes) {
                $batch = $this->getBatch(); //All this does is check for a batch ID and if it is present, retrieve the batch from Laravel's Bus as defined in the docs

                if (!$batch) {
                    return 'No Batch Found';
                } else {
                    if($batch->finished()) { return 'Finished'; }
                    elseif($batch->cancelled()) { return 'Cancelled'; }
                    elseif($this->inProgress) { return 'In Progress'; }
                    elseif (!$batch->finished() && $batch->failedJobs > 0) { return 'Failed'; }
                    elseif (!$batch->finished() && $batch->pendingJobs > 0) { return 'Waiting'; }
                    else { return 'Unknown Status'; }
                }
            },
        );
    }
protected function batchStatus(): Attribute
    {
        return Attribute::make(
            get: function (mixed $value, array $attributes) {
                $batch = $this->getBatch(); //All this does is check for a batch ID and if it is present, retrieve the batch from Laravel's Bus as defined in the docs

                if (!$batch) {
                    return 'No Batch Found';
                } else {
                    if($batch->finished()) { return 'Finished'; }
                    elseif($batch->cancelled()) { return 'Cancelled'; }
                    elseif($this->inProgress) { return 'In Progress'; }
                    elseif (!$batch->finished() && $batch->failedJobs > 0) { return 'Failed'; }
                    elseif (!$batch->finished() && $batch->pendingJobs > 0) { return 'Waiting'; }
                    else { return 'Unknown Status'; }
                }
            },
        );
    }


I have this attribute as a field in my table and I want to be able to filter on it with a Select filter, but since it isn't a DB field, I can't figure out how to setup the filter. Any help would be greatly appreciated!
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Filter from Accessor
FilamentFFilament / ❓┊help
2y ago
How to sort the table using model accessor
FilamentFFilament / ❓┊help
2y ago
How to create record in a model from a table widget
FilamentFFilament / ❓┊help
3y ago
how get data from filter table ?
FilamentFFilament / ❓┊help
3y ago