Filter from Accessor

Hello Together, i'm using Laravel Venture for Workflow Jobs, and i have set in my model a Accessor. That gives me for every row a output if the workflow is running or failed or was canceled as string. in my Table in Filament this works very well and every row has his Data from the Accessor. now i want to implement a filter to the Table where i can filter via the accessor string, but this don't work out until now. this is my Accessor in the Model :
public function getWorkflowStatusAttribute()
{
if ($this->cancelled_at != Null) {
return 'Abgebrochen';
} else if ($this->failedJobs()->isNotEmpty()) {
return 'Fehlgeschlagen';
} else if (!$this->allJobsHaveFinished()) {
return 'Läuft';
} else if ($this->allJobsHaveFinished()) {
return 'Abgeschlossen';
}
}
public function getWorkflowStatusAttribute()
{
if ($this->cancelled_at != Null) {
return 'Abgebrochen';
} else if ($this->failedJobs()->isNotEmpty()) {
return 'Fehlgeschlagen';
} else if (!$this->allJobsHaveFinished()) {
return 'Läuft';
} else if ($this->allJobsHaveFinished()) {
return 'Abgeschlossen';
}
}
any idea how i can filter by the returned Strings ? 🙂 Thanks
Solution:
@Frittenfred it doesn't work for a reason: accessors are called and values formed AFTER the main query of Eloquent which contains all the filtering. Maybe you can make filters work by reworking how your accessors work to make the same logic called in a custom filter but it's quite a "hacky" way....
Jump to solution
3 Replies
Solution
Povilas K
Povilas K8mo ago
@Frittenfred it doesn't work for a reason: accessors are called and values formed AFTER the main query of Eloquent which contains all the filtering. Maybe you can make filters work by reworking how your accessors work to make the same logic called in a custom filter but it's quite a "hacky" way.
Frittenfred
FrittenfredOP8mo ago
yeah i was thinking that allready, no SQL Row, so no Query. okay, thank you very much @PovilasKorop 🙂
Povilas K
Povilas K8mo ago
Thinking about it, it would be a pretty interesting challenge to make it work, putting your accessor logic elsewhere in some kind of a Service class that would be reused by both filter and accessor. But unfortunately don't have time atm to play around with it 🙂
Want results from more Discord servers?
Add your server