Rich domain models with Active Record
HTML-код
- Опубликовано: 9 фев 2025
- Coding starts at 03:00
👨💻 Learn Test-Driven Development with Laravel!
tddwithlaravel...
Sign up to 30 Days of Laravel 👉🏻 30daysoflarave...
👨💻 Sign up to my newsletter and receive PHP, JS and Laravel news in a weekly-basis:
subscribe.mate...
🎉 Party up:
/ mateusjatenee
/ mateusjatenee
/ mateusguimaraes
Thanks for watching!
Please post more frequently! 😊
What a timing, I was just researching about rich domain model with eloquent!
So good demonstration, especially with such practical examples. Great video!
Thanks, glad you liked it!
I would love to see you create a paid course on building a complete e-commerce platform as a Laravel package that is modular, extendable, and reusable.
Great topic, thank you!
At 19:21, you said you'd have a command and wrap it inside a transaction, so you wouldn't need to have DB::transaction() inside the place() method. Why is that? Isn't it a "good" practice to make sure that the place() method is always an "atomic" operation? What if someone called the place() method outside a transaction?
Yes and no - in non-AR implementations, you typically mutate state and delay persistence to the end of the operation, so you have a small window in which DB operations are going to occur, typically within a repository - in that case, handling DB transactions is a bit straightforward.
With AR, persistence might happen in several places, so it could be interesting to ensure the methods themselves are atomic.
OTOH, you can have several operations happen within a command, and more often than not you want the entire command to be a single unit of work. An option is to leverage nested transactions (through Eloquent), so you can have the command be atomic, and also the method (if it persists anything).
Yeah, makes sense. Thanks for the answer. In my opinion, you're the best regarding Laravel and advanced topics. I really like the way you code and the examples you use, you know how to go deep. Congratulations.
Great video. I wish you would create a router from scratch (laravel inspired) named routes, groups, etc etc maybe even middleware handling. wouldnt mind paying for such a course.