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