lukeraymonddowning / poser

Create class based model factories in Laravel applications in seconds.
MIT License
277 stars 10 forks source link

`afterCreating` will now also work on related models. #43

Closed lukeraymonddowning closed 4 years ago

lukeraymonddowning commented 4 years ago

@AlanHolmes I've been playing with this and think we're finally there. Would you check this out before I merge it in?

AlanHolmes commented 4 years ago

Cool, I'll take a look later (or tomorrow if I dont get chance)

One thought, it would be cool if for the linked models closure it also passed the model it was linked from, in the examples case it would be user and then customer as a second param.

lukeraymonddowning commented 4 years ago

One thought, it would be cool if for the linked models closure it also passed the model it was linked from, in the examples case it would be user and then customer as a second param.

Would this be infinitely deep? So if a user has customers that have books, would afterCreating in the book relationship receive ($book, $customer, $user)?

AlanHolmes commented 4 years ago

That could become a nightmare to track, but cool if possible.

But thinking about the afterCreatingState, if I was using that on a user, and then created some customers in it, then I would have user and customers, but not books (well I would on the eloquent method, depending on the order it was ran in).

And I think, from a sanity point of view that would be the easiest to replicate.

lukeraymonddowning commented 4 years ago

All sorted in the latest commit 👍🥳

AlanHolmes commented 4 years ago

🔥 This works perfectly 😀