DEV Community

Restore missing Command Bus in new Laravel versions

Mateusz Cholewka on March 22, 2022

Command Bus is a very powerful pattern, which can help you in decoupling your application modules. You can in an easy way separate small actions, a...
Collapse
 
vgaldikas profile image
Vytautas

Where does the fromRaw in ReserveResource come from? Is the implementation simply ommited in the class definitinion for the sake of brevity? Or is there some other magic going on?

Collapse
 
mtk3d profile image
Mateusz Cholewka • Edited

No, there is no magic 😄. That's just a static method in ReserveResource that takes list of parameters, and builds ReserveResource object based on them.

Collapse
 
vgaldikas profile image
Vytautas

And another question.. How would you recommend to go about receiving the outcome of the Reservation. Just a separate query service?

Collapse
 
mtk3d profile image
Mateusz Cholewka

It really depends on your needs 😉. Just a good practice is to keep reads and writes separate.

Yes, it could be a separate query bus, that sends queries and returns data. You can also build a read model, which is a simple CRUD implementation used directly in the controller, and just update it through events in your system. Even updating the database directly through events and then retrieving data using SQL could be fine as far as you keep your reads and writes separately.

I've used a solution with CRUDs updated through events, in my karting app, you can check it out here 😄: github.com/mtk3d/karting

Collapse
 
carlosvazquez profile image
Carlos Vazquez

Why there's not comments?! Command Bus is an amazing pattern and should be implemented as a common in many projects.
Thanks for your post.