Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raygun's avatar

How to do a full text search in laravel 5

I have been searching exhaustively how to do a full text search in laravel from multiple tables and have found nothing. How do Implement this? any help will be magnificent

0 likes
5 replies
RobinMalfait's avatar

Use ElasticSearch or Lucine, I don't know, use the right tool for the right problem :)

jekinney's avatar

You could right or implement your own, but I will assume it maybe beyond your scope of abilities( mine too). Laracasts has a few lessons on searching, one very old but still very relevant plus the brand new series that covers a third party service.

PedroM's avatar

+1 to Elastic, regarding the lessons on laracasts last months, and dont get me wrong, this appear as is not laracasts anymore, is more vuecasts or advertisingcasts (with 3rd party services). I stop my subscription months ago when take a month with freebies and then 3rd party (paid) services. Now I try to give back to the community helping on this forum when I have some spare time. Sorry the offtopic.

2 likes
kfirba's avatar

@raygun There is actually a way to do it. Take a look at Eloquence.

It is an amazing package that extends eloquent abilities and it does it well. It was built in performance in mind which is why I love it. Thank @JarekTkaczyk for that ;)

5 likes
davidfaux's avatar

In the past I've resorted to query builder for full text searches

$query = $this->document
            ->join('docindexes', 'docindexes.document_id', '=', 'documents.id')
            ->wherePublished(1)
            ->whereNull('documents.deleted_at')
            ->whereRaw("match(document) against (? in boolean mode)", [$term])
            ->orderBy('score', 'desc');

return $query->get([
    'documents.id',
    'documents.description',
    'docindexes.document',
    'documents.filename',
    'documents.code',
    \DB::raw("MATCH (document) AGAINST ('".$term."') AS score")]);

3 likes

Please or to participate in this conversation.