0

I'm Confusing what is the advantage between commands and events however we can achieve our requirement by using commands what events can do then why use of events

Mr.Throg
  • 925
  • 6
  • 21
  • 1
    have a read here http://stackoverflow.com/questions/4962755/why-are-commands-and-events-separately-represented/ and http://stackoverflow.com/questions/2952956/wpf-commands-vs-events-advantages-disadvantages – aimme Aug 04 '16 at 10:37

1 Answers1

0

Yes, in some way they are the same. I think (correct me if i'm wrong) it is just for separating code and creating cleaner applications.

For example console commands are more likely to be used in the 'console' by Artisan. Events however are used inside the application and fired when some sort of interaction takes place.

However when you want to call some script (command or event) you always have to trigger it manually.

Command: Artisan::call('email:send', $somedata);

Event: Event::fire(new SendEmailEvent($somedata));

I prefer to use events when something took place inside my application (like someone uploaded a file) and commands to fire scripts to maintain the application (like cron jobs etc).

Hope this helps you choosing :)

Thomas Van der Veen
  • 3,136
  • 2
  • 21
  • 36