Why Not Custom Field That Extend Filament Field In Code Quality Tips
In v4.0.0-beta in code quality tips https://filamentphp.com/docs/4.x/resources/code-quality-tips#using-component-classes it suggest that we make a class that return the filament field or column then use that class but I think that there is better tip is to suggest that we use OOP stuff which is "inheritance" like this code
then used that class in our form. Its much better because it will allow us to add more functionality to the column it self and use the existing code that
TextInput
provide in our custom methods. This can be applied to tables columns, infolist entries, actions and more
what do you think?4 Replies
Any ideas?
I think it's written like that in the docs because it's easier for beginners, its basicly the same thing but when extending it's more customizable. But if I'm wrong I'd also like to know why it's written this way in the docs
I think it’s just that OOP is not needed for those small examples. Also: if the base class changes on won’t affect the parent class.
Maybe @Dan Harrin can shed some light on more benefits.
if you use inheritance you cant redefine the make() method with your own params, which is super useful if you “require” data to be passed in to use a field
i used to think setUp() was better but I changed my mind after discussions with others
its also safer not to call internal methods on the field, use the public api only
but these are tips not guidelines. do as you wish