Section of fields that I can re-use over multiple resources/custom pages
I want to make a custom field like
SEOData::make()
which contains a few fields that go to a relationship of that model.
But I dont know if a custom field is the way to go, because I dont want to make a custom blade etc. It basically needs to be a reusable set of fields.
Because multiple resources have a relationship to a model called PageMeta.php
, and I want to implement those fields out of that database table into multiple resources/custom pages.
I can just copy and paste those fields over and over again, but then if I need to change it, I need to do it on multiple places which of course isn't what you want.
What's the best way to do this?3 Replies
You can define them on a resource or on a separate class as a static method. I've used a similar method in a resource class where I created a custom delete action which I needed in two places.
I added the following code in my
CoinsPackResource
class as I was re-using this only in the same resource but you can create a separate class somewhere else and define your custom methods on it.
PS: I'm not familiar with Livewire and component stuff but if there's a better approach like a custom component then you should go with that.You don’t have to have custom views. You can just return an existing setup of form components. https://gist.github.com/awcodes/9784de531aea8e3bdba772a55958a999
Exactly what I am looking for!
Thanks to both of you for answering! 🚀