Model events: how to access posted data? #622
-
I need to intercept a POST when creating a record to manipulate data . |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @realtebo! Also, if you just want to manipulate data on your model before save, most probably you need a mutator. |
Beta Was this translation helpful? Give feedback.
-
I am creating model events /saving and saved/ inside setupCreateOperation I resolved using request() |
Beta Was this translation helpful? Give feedback.
Hey @realtebo!
I'm not sure in which part of the code you are, but I believe you can use the
request()
at any place.So most probably, if you want to intercept a request to manipulate data you can use the event
saving
(that gets called before any save, create/update) and there you can access therequest()
data.Also, if you just want to manipulate data on your model before save, most probably you need a mutator.
Take a look here; https://laravel.com/docs/10.x/eloquent-mutators#defining-a-mutator