This looks, to me at least, a task for a custom cast:
https://laravel.com/docs/9.x/eloquent-mutators#custom-casts
I would put it on App/Casts as suggested by Laravel docs, but there is no official convention.
I found this lesson about it:
Hi,
I'm storing my models in a MySQL database. One field of the model (Device) is a JSON field where all the settings will be stored. Not every instance of Device will have the same JSON structure and I want to create a class that is responsible of getting and setting properties in this JSON object. This class would have the responsibility to check if a (chain of) property exists and if so get or set it depending on the instruction.
My question is where should I put this kind of logic when following the Laravel way? The controller seems like a bad place to put his. And the Model would quickly become a very big file. Are there any lessons on Laracasts that may help me with this?
Thanks in advance!
Please or to participate in this conversation.