TIP 03 / 100

Small Cheat-sheet for Using Full-text Search with Laravel on Mysql.

Migration

code
Schema::create('comments', function (Blueprint $table) {
     $table->id();
     $table->string('title');
     $table->text('description');

     $table->fullText(['title', 'description']);
});

Natural language

Search for something

php
Comment::whereFulltext(['title', 'description'], 'something')->get();

Natural language with Query Expansion

Search for something and use the results to perform a larger query

php
Comment::whereFulltext(['title', 'description'], 'something', ['expanded' => true])->get();

Boolean mode

Search for something and exclude else

php
Comment::whereFulltext(['title', 'description'], '+something -else', ['mode' => 'boolean'])->get();