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