Home » Php » php – Laravel Command-Bus, When to use self handling commands?

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

Posted by: admin July 12, 2020 Leave a comment


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?

How to&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.