Avoid duplicate code

Good morning, Lets say I have two resources: -> Brands -> Ingredients Both have a relation with products. So for both resources I have separate a relationmanager to products. Both relationmanagers have a table with the same code for table. My question is how what are ways to abstract this code so that I only have the tableoverview for products once? Thanks.
Solution:
You can basically do it however you want. One option is to create an invokable class that accepts $table and modifies it with columns etc. Then you can invoke that for each resource in the table method
Jump to solution
2 Replies
Solution
Dan Harrin
Dan Harrin7mo ago
You can basically do it however you want. One option is to create an invokable class that accepts $table and modifies it with columns etc. Then you can invoke that for each resource in the table method
Dan Harrin
Dan Harrin7mo ago
or you can create a product resource and call ProductResource::table($table) it sounds patronising but its just php so you can refactor the code in any way you know how
Want results from more Discord servers?
Add your server