Full text search in Laravel

Option 1 - Use a simple Eloquent query

QUERY CALL IN CONTROLLER
Now you can use the below query to call in table using

SELECT * FROM `posts` WHERE MATCH(title,body) AGAINST('testing post' IN BOOLEAN MODE);

or

Post::whereRaw('MATCH (title, body) AGAINST (?)' , array($search))->get();

Use the following when you want to query the exact phrase in the database:

SELECT * FROM `posts` WHERE MATCH(title,body) AGAINST('"testing post"' IN BOOLEAN MODE);

Reference:

Option 2 - Use Laravel Scout

Laravel Scout provides a simple, driver based solution for adding full-text search to your Eloquent models. Using model observers, Scout will automatically keep your search indexes in sync with your Eloquent records.

Currently, Scout ships with Algolia and MeiliSearch drivers. In addition, Scout includes a “collection” driver that is designed for local development usage and does not require any external dependencies or third-party services. Furthermore, writing custom drivers is simple and you are free to extend Scout with your own search implementations.

Reference:
https://laravel.com/docs/8.x/scout

<?php

namespace App\Traits;

trait FullTextSearchTrait {

    public function scopeFullTextSearch($query, array $columns, string $text) {
        $col_text = implode(',', $columns);
        return $query->whereRaw("MATCH ($col_text) AGAINST ('$text')");
    }

}

?>