The --method flag in the above comment is optional, and if not provided, the handler will register with the handle method.
Even the --event is also optional but we strongly advise to always provide it, because when it's not provided, yuga-auto-events will be the registered event
If the provided event name is a valid php class, the class will be injected in the event method provided as below.
<?php/** * This file was auto-generated. */namespaceApp\Handlers;useApp\Events\Test;useYuga\EventHandlers\HandlerInterface;classWhenAuthenticatedimplementsHandlerInterface{/** * Event Handler Logic here * @param\Yuga\Events\Dispatcher $event * @returnmixed */publicfunctionhandle($event) {returnnull; }/** * Your Event Handler Logic here * @paramApp\Events\UserAuthenticated $event * @returnmixed */publicfunctionisAuthentic(UserAuthenticated $event) {returnnull; }}
And the event class should be as below:
<?phpnamespaceApp\Events;useYuga\Events\Dispatcher\Dispatcher;classUserAuthenticatedextendsDispatcher{/** * Event Name */protected $name ='on:userauthenticated';}
In which case you can no longer dispatch the event like so
event('on:userauthenticated');
inside of any controller or view-model for that matter, this is because of the contract provided in the event handler, so we are left with the option of: