F
Filamentβ€’14mo ago
ziolupo

Error in extending tables

I would like to extend from Tables for creating my own class (in filament 3) I created an empty class: namespace App\Tables\Components; use Filament\Tables\Table; class MyTable extends Table{ } but if I try to use MyTable in this way in a resource file: public static function table(MyTable $table): MyTable I have this error: Declaration of App\Filament\Resources\ExhibitionResource::table(App\Tables\Components\MyTable $table): App\Tables\Components\MyTable must be compatible with Filament\Resources\Resource::table(Filament\Tables\Table $table): And I cannot understand why.
Solution:
The abstract Resource names the specific Table class which must be implemented in that particular scenario, instead of specifying a contract. https://github.com/filamentphp/filament/blob/aa609c8f1214e6c49f1625d006a4d6739bcc2e5c/packages/panels/src/Resources/Resource.php#L151-L154
GitHub
filament/packages/panels/src/Resources/Resource.php at aa609c8f1214...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Jump to solution
9 Replies
krekas
krekasβ€’14mo ago
why do you want to extend it?
Filament
Filamentβ€’14mo ago
Please ask about the actual problem you're trying to solve, instead of your attempted solution. https://xyproblem.info
ziolupo
ziolupoOPβ€’14mo ago
It just an experiment to see how flexible can be using FIlament.
krekas
krekasβ€’14mo ago
experiment of what? what you try to achieve?
Solution
DrByte
DrByteβ€’14mo ago
The abstract Resource names the specific Table class which must be implemented in that particular scenario, instead of specifying a contract. https://github.com/filamentphp/filament/blob/aa609c8f1214e6c49f1625d006a4d6739bcc2e5c/packages/panels/src/Resources/Resource.php#L151-L154
GitHub
filament/packages/panels/src/Resources/Resource.php at aa609c8f1214...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
DrByte
DrByteβ€’14mo ago
But it still begs the question: what would you want to do in your extended version of that particular class?
ziolupo
ziolupoOPβ€’14mo ago
Honestly speaking I don't have anything that I want to do with the new class...b ut I can easily find. For example a class "compact", or a class where I can dynamically change the padding. But the idea was just having a new class for playing.
DrByte
DrByteβ€’14mo ago
Understandable. Unfortunately in this specific case, that's not the right approach. Instead, Filament lets you set global configurations on many of its components, so that's one thing you can explore. Another thing could be to set up some Traits that you add to the various classes if you want to add the same functionality to several classes with one line of code. But I've not run into a need for that, at least not when it comes to major components like Resources and Tables. (I do use traits for reusable Form fields, since some of those are used in multiple resources and the consistency is super handy.) If it's padding you're interested in controlling, you have a lot of control in the CSS, whether by targeting individual named elements with css selectors in your own custom css, or by recompiling the css overall.
ziolupo
ziolupoOPβ€’14mo ago
Thanks DrByte. I investigate further "under the hood" and it's exactly as you are saying. About the result, I already achieved that with CSS or by changing the original code (I know that is something not to do... πŸ™‚ ... but as I was saying from the beginning, I was more interested in the possibility, without a particular ussue or problem to be solved. Thanks again
Want results from more Discord servers?
Add your server