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:Jump to 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-L154GitHub
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
9 Replies
why do you want to extend it?
Please ask about the actual problem you're trying to solve, instead of your attempted solution. https://xyproblem.info
It just an experiment to see how flexible can be using FIlament.
experiment of what? what you try to achieve?
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-L154GitHub
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
But it still begs the question: what would you want to do in your extended version of that particular class?
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.
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.
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