Folks - it was brought to my attention I mistakenly passed the Command DTO to the handler's constructor. I somehow didn't notice this while coding and/or recording - my apologies for that. The DTO should be passed to the handler's handle method - the constructor should be used for its dependencies. I'll possibly re-record this video. Thanks for the comment @mnavarrocarter
@mnavarrocarter Жыл бұрын
I think the command DTO shouldn't be passed in the constructor of the handler. The constructor of the handler should be for its dependencies. The command DTO should be the argument of the handle method. That way, you can reuse the same handler reference (potentially fetched from a container) to handle multiple commands. The way you have it setup now requires to create a brand new handler for every command you want to handle.
@martingrega Жыл бұрын
This.
Жыл бұрын
You're right. I didn't notice until now that I mistakenly passed it in the constructor. Thanks for letting me know - I'll have to re-record this video.
@hhaahh86 Жыл бұрын
wow those "Actions" are definitely better than ordinary functions, because of that fancy wrap with "class" and handle method. *going back to write some clojure.*
Жыл бұрын
Have a good one
@TLJAFAR Жыл бұрын
Thanks 👍
@ahirhiten7326 Жыл бұрын
Which vscode theme is that
@carlosescobar599511 ай бұрын
That's not vscode, it's Phpstorm
@MarlonLCosta Жыл бұрын
Eu já usava esse pattern mas sem saber, usava como "usecase"
@НазарПанасюк-у8я Жыл бұрын
unfortunately, this example doesn't explains to me this pattern. if i have validation and i need to take ONLY validated entries from the request i just do simply as `Post::create($request->validated());` . that's it. the practical usage of the explained pattern is not yet clear to me.
Жыл бұрын
You might be right - in hindsight, this might not have been a good example. Think whenever you have to coordinate different models (models in general, not necessarily eloquent models) and services to achieve certain behavior - think about “purchasing a product”. You’d need to hit a payment gateway, do some validation on your end (is the product in stock? etc.), create several records in the DB - that’s what you could defer to one (or many) commands. Take a look at the Actions a Jetstream application comes with!
@НазарПанасюк-у8я Жыл бұрын
@ thanks for the answer. i'll keep this in mind :)