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