Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Command-Bus, When to use self handling commands?

As you may know, command bus has been implemented in laravel 5. and there are two way to handling commands in laravel 5.

  1. Handle by a command handler
  2. Handle by command itself (self handling commands)

What's the main different of these ways? When to use self handling commands and when to handle commands by their related command handler?

like image 560
Behzadsh Avatar asked Feb 14 '15 07:02

Behzadsh


1 Answers

It is another one of the Laravel features that really comes down to 'it depends'. If you were building a large enterprise application - they you would want to separate the command from the handler - as this adheres to SRP.

But for most of us in most cases - the self handling command would be more than sufficent. I use self-handling commands and I quite like them.

This question was actually asked by Taylor Otwell and Jeffrey Way on twitter recently. Taylor Otwell himself said he wanted a reason to not just use self-handling commands.

Ross Tuck also gave a deep insight into this exact topic here as well that is worth reading for a different perspective on why not to use them.

like image 132
Laurence Avatar answered Nov 14 '22 22:11

Laurence