Accessing $request vars in observer
So I ran into this problem multiple times but always changed it differently. I'm now posting this hoping there is an easier solution. Sometimes I use fields in my form (for recurring event for example) that I don't need saved in the database.
If I don't specify the fields in the fillable array (on the model) then they don't appear in the observer:
I know i should maybe do this with a:
->mutateFormDataUsing()
But I would have to do that at multiple places (in the resource and livewire page with fullcalendar for example), and personally I love putting this logic in an observer so I always know where to look.
So my question: how can I access $_POST vars (or $request->inputs) in an observer? Without adding them as a fillable field?
2 Replies
I think your aproach is wrong. If you want to use a function in multiple places, you can use service pattern.
I think you are probably right. I am not familiar with service patterns. For now i think i will handle the logic in the resource and do the other part in the observers. Part of the work should anyways be done in a queue i think. I’m pretty new to laravel so still figuring out what the best way to structure everything is.