Skip to main content
Quick Tip

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

Enjoyed This Tip?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses on Laravel Daily

Next.js Basics for Laravel Developers

11 lessons
58 min

Laravel 13 Starter Kit Teams and Customizations

10 lessons
33 min

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read