DB Models and EloquentTIP 03 / 100
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();