Replies: 2 comments 12 replies
-
What's your use case for a theoretical Typically |
Beta Was this translation helpful? Give feedback.
12 replies
-
Since there is no much interest in the new event and there is a workaround (thanks to @henzeb) , I better close the discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The idea is to add a
making
event to the Eloquent model which is going to be bound to theModel::make()
method (as thecreating
event is bound to theModel::create()
method). Why the framework needs it?Use case
Let's assume, there is a Post model and we want to automatically generate a slug from a title (when a slug is not provided). I tried to implement this functionality through Mutators (but it doesn't work because you need to call a
slug
explicitly to mutate it) and through the constructor (but I didn't find a way to access the models' attributes in there - it seems there is no way to do it).The only working way, which I've found, is to use the Model events with closures to adjust the slug.
This works for the
create()
method,but this does not work for the
make()
method., it's not possible to have the symmetrical behavior for
Post::make()
andPost::create()
because no events are bound tomake
.Btw, my use case is not unique. There are other cases related to the dynamic attributes generation, for example:
I would like to propose to add the
making
event and bound it to theModel::make()
method. It seems logical for this event to exist.Beta Was this translation helpful? Give feedback.
All reactions