Creating table filter in a trait
I have a table filter that works perfectly when created directly in my resources, but fails when I try to move it to a trait (I have multiple resources with the same filter).
How I'm calling it:
Doesn't cause an error; just basically clears the table. I suspect I'm messing up something related to static methods, but I'm not sure. Can anyone point out what my mistake is? Would it be a better approach to just extend the Filter class similar to how the trashed filter extends the ternary filter class? Thanks
Solution:Jump to solution
Laravel macros are new to me. While trying to find documentation on them, I eventually came across Dan Harrin's recent laracasts series, and it turns out one of his videos creates a custom filter and turns it into a reusable class like I was thinking about https://laracasts.com/series/build-advanced-components-for-filament/episodes/11. So I'm going to go with that approach, but now that I know about Laravel macros, I'll definitely be spending some time learning them.
Edit: while creating the class, I realized I forgot to import my SoftDeleteScope class into the trait. I didn't realize that would fail silently....
2 Replies
You could create a macro in the AppServiceProvider
Solution
Laravel macros are new to me. While trying to find documentation on them, I eventually came across Dan Harrin's recent laracasts series, and it turns out one of his videos creates a custom filter and turns it into a reusable class like I was thinking about https://laracasts.com/series/build-advanced-components-for-filament/episodes/11. So I'm going to go with that approach, but now that I know about Laravel macros, I'll definitely be spending some time learning them.
Edit: while creating the class, I realized I forgot to import my SoftDeleteScope class into the trait. I didn't realize that would fail silently.