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