', '@', '(', ')', '~']; $term = str_replace($reservedSymbols, '', $term); $words = explode(' ', $term); foreach($words as $key => $word) { /* * applying + operator (required word) only big words * because smaller ones are not indexed by mysql */ if(strlen($word) >= 3) { $words[$key] = '+' . $word . '*'; } } $searchTerm = implode(' ', $words); return $searchTerm; } /** * Scope a query that matches a full text search of term. * * @param \Illuminate\Database\Eloquent\Builder $query * @param string $term * @return \Illuminate\Database\Eloquent\Builder */ public function scopeSearch($query, $term) { $modelPlural = $this->getTable(); $modelSingular = str_singular($modelPlural); $columns = implode(',',$this->searchable); return $query->join($modelSingular . '_translations', $modelPlural . '.id', '=', $modelSingular . '_translations.' . $modelSingular . '_id') ->select($modelPlural . '.*') ->where($modelSingular . '_translations.locale', app()->getLocale()) ->whereRaw("MATCH ({$columns}) AGAINST (? IN BOOLEAN MODE)", [$this->fullTextWildcards($term)]); } }