Laravel 9 FullText Index feature and using it with Where Clauses?

Laravel 9 Full Text Indexes

Laravel 9 FullText Index feature using with whereFullText and orWhereFullText methods may be used to add full text “where” clauses to a query for columns that have full text indexes.

Fulltext indexes and where clauses

If you are using MySQL or PostgreSQL in your Laravel 9 application, then it includes better support to use the fulltext method on the column definitions in your migration files to generate full-text indexes.

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('content')->fullText();
        $table->timestamps();
    });
}

Then, you can use the whereFullText and orWhereFullText methods to add full-text where clauses to your queries.

$posts = Post::whereFullText('content', 'john doe')->get();

To get to know more about the Laravel, you can check these articles too

Please follow and like us:

Related Posts

Leave a Reply

Share