[], 'after' => ['create'], ]; /** * Handle the ProposalActionEvent. * * @param ProposalActionEvent $event * @return mixed */ public function handle(ProposalActionEvent $event) { $function = Str::camel($event->action); return $this->$function($event); } /** * Create a new $proposal. * * @param ProposalActionEvent $event * @return void */ public function create(ProposalActionEvent $event) { $client = $event->proposal->client; Notification::send($client, new ProposalActionNotification($event)); } /** * Handle the ProposalActionEvent as a listener. * * @param ProposalActionEvent $event * @return mixed */ public function asListener(ProposalActionEvent $event) { if ($this->isAllowed($event)) { return $this->handle($event); } } /** * Check if the event action is allowed. * * @param ProposalActionEvent $event * @return bool */ private function isAllowed(ProposalActionEvent $event) { if ($event->when == 'before' && !in_array($event->action, $this->allowedActions['before'])) { return false; } if (($event->when == 'after' && !in_array($event->action, $this->allowedActions['after'])) ) { return false; } return true; } }