/** * This method will bind all events to the eloquent model created, updated or deleted events. * Note the events are not the creating, updating or deleting events, as these would possibly * index data that might change due to a model observer adjusting data. * @param Searchable $type * @param array $with */ public function regularAutoIndex(Searchable $type, array $with) { /** @var Dispatcher $dispatcher */ $dispatcher = $this->container->make('events'); $me = $this; foreach ($this->listeners as $event => $listener) { $trigger = $type->getSearchableEventname($event); $type->setSearchableService($me); $type->setSearchableIndex($me->config->getIndex()); if ($trigger) { $callback = function (Searchable $type) use($me, $listener, $with) { return $me->{$listener}($type); }; $dispatcher->listen($trigger, $callback, 15); } } }