[], 'after' => ['create'], ]; /** * Handle the CouponActionEvent. * * @param CouponActionEvent $event * @return mixed */ public function handle(CouponActionEvent $event) { $function = Str::camel($event->action); return $this->$function($event); } /** * Create a new $coupon. * * @param CouponActionEvent $event * @return void */ public function create(CouponActionEvent $event) { $client = $event->coupon->client; Notification::send($client, new CouponActionNotification($event)); } /** * Handle the CouponActionEvent as a listener. * * @param CouponActionEvent $event * @return mixed */ public function asListener(CouponActionEvent $event) { if ($this->isAllowed($event)) { return $this->handle($event); } } /** * Check if the event action is allowed. * * @param CouponActionEvent $event * @return bool */ private function isAllowed(CouponActionEvent $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; } }