Small cheat-sheet for using Full-Text Search with Laravel on MySQL

Migration

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

Natural language

Search for something

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

Natural language with Query Expansion

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

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

Boolean mode

Search for something and exclude else

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

Tip given by @w3Nicolas

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 68 courses (1183 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses