/** * Define your route model bindings, pattern filters, etc. */ public function boot() { $me = $this; $parser = $this->parser; /* * Search through any columns with score relevance. * * @param array|string $keywords * @param array $columns * @param string $groupBy * @param boolean $fulltext * @param float $threshold * @return $this */ Builder::macro('search', function ($keywords, array $columns, $fulltext = true, $threshold = null, $groupBy = 'id') use($me, $parser) { $words = is_array($keywords) ? $keywords : $parser->parseQuery($keywords, $fulltext); $columns = $parser->parseWeights($columns); if (count($words) && count($columns)) { // Macro is scoped for Query\Builder, so let's trick it by calling // in a closure bound to this Searchable class. This allows us // to leave all the implementation methods below protected. $closure = function () use($me, $words, $columns, $groupBy, $threshold) { $me->query = $this; $me->buildSubquery($words, $columns, $groupBy, $threshold); $me->query = null; }; call_user_func($closure->bindTo($this, get_class($me))); return Query::copy($this)->setThreshold($me->threshold); } return $this; }); }