Datadog collects and monitors your PHP app metrics and distributed traces in real-time with application performance monitoring. Decrease downtime and performance issues with Datadog APM by tracing requests across service boundaries and drilling into individual traces end-to-end with flame graphs. Start your 14-day trial for free today.
Follow me on Twitter. I regularly tweet out programming tips, and what I myself have learned in ongoing projects.
Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer.
Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.
Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.
Amazing 🤯 Nice "under the hood" explanation 👍
I love this style! Even if I name it "fluent API" instead of pending object.
For me pending objects are the ones running logic on destruct. 🤔
thank you! I will test this in a future project
@freekmurze and not to forget @taylorotwell this is genius. Of course I have consumed this type of fluent code, but never constructed a pending object pattern class before! Looking forward to trying it out!
Thanks. Also thanks for the video. Interesting to see use of destructor. Am I right in thinking they are called the moment the final reference to the object is removed? Or is it when the object is garbage collected?
Mostly I use something that sound nice and logical in the context where I use this pattern.
Interesting. Looks like builder pattern. One benefit I see of the builder pattern is that, by convention, the final (or finishing) method is build(). How do you know which is the 'finishing method' is for the pending object, without have to look at all method return types?
It's just fancy name for classic Builder pattern.
Nice tip. But I am a bit confused.
Is there any difference between this and method chaining?
Or is “pending object” another name for method chaining?
It could be done returning the model it self, instead of a PendingModel. But I think the goal behind the creation of a pending object is to avoid things that could lead to mistakes. Like reach for a relationship when the model itself isn't persisted yet. Am I right?
Those videos are great, but if you don't mind, could you enable the video speed option? I like to watch everything in 2x 😁
I see some great improvements coming up in 2020 🙌
Great explanation and a great video 👌
Just beware: this breaks when doing it in Tinker, since Tinker keeps a reference to the object.
Cool, thanks. Is that pending object the correct name for this pattern? I didn't find other articles about this pattern.
Thanks, besides being awesome, taking the time to produce posts and videos on awesome tips is what makes you stand apart.