Supercharge Search in Laravel Using Laravel Scout
⚡ Quick Setup (Simple Steps)
1️⃣ Install Scout
composer require laravel/scout
2️⃣ Add Trait to Model
Example: Product search
use Laravel\Scout\Searchable;
class Product extends Model
{
use Searchable;
}
That’s it. Your model is now searchable.
3️⃣ Import Existing Data
php artisan scout:import "App\Models\Product"
Scout pushes your data to the search engine.
🛍 Real Project Example: Product Search
Instead of this:
Product::where('name', 'like', "%$query%")->get();
Use Scout:
Product::search($query)->get();
Done.
It’s:
- Faster
- Cleaner
- Scalable