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

[NEW] Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks

7 lessons
43 min read

Testing in Laravel 13 For Beginners

26 lessons
1 h 41 min read

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read