In this episode, we're diving into how to index your products into Meilisearch using Laravel Scout. First up, we get Scout installed and set up in our Laravel project, and we configure it as the bridge connecting our app and Meilisearch. We talk through the installation steps, making sure you have both the necessary PHP library for Meilisearch and the server itself up and running locally. If you're on a Mac, it's as simple as brew install meilisearch
!
After getting everything running, we walk through the process of making your Product model "searchable" by adding the appropriate trait. We also cover how to publish the Scout config file, and how to set up your .env with the right Meilisearch host and key.
With the basics ready, we learn how to use the Artisan commands to import (index) your product data into Meilisearch and take a peek at it using the Meilisearch dashboard. Then, we explore customizing what gets indexed by creating the toSearchableArray
method on our Product model. You see how to control exactly which fields are sent into Meilisearch, like the product's title, slug, price, and even plans to add category IDs for advanced filtering.
Lastly, we run into a small hiccup — the relationship for categories isn't connected yet! No worries, though; we identify what needs to be fixed and set up the plan to tackle it in the next lesson. So by the end of this episode, you'll have your products searchable in Meilisearch, know how to pick which fields are indexed, and be ready to continue with adding filtering options soon.