This is an implementation of Laravel Scout-Meilisearch in Laravel. A blog about this can be found here: Simple and Advanced Search With Laravel Scout and Meilisearch | Fajarwz.
composer install
cp .env.example .env
php artisan key:generate
- Create a database and connect it with Laravel with filling the DB name in
DB_DATABASE
- Adjust
DB_USERNAME
- Adjut
DB_PASSWORD
php artisan migrate --seed
php artisan serve
Download the Meilisearch app
# Install Meilisearch
# Windows user: you can use CMD to run this command
curl -L https://install.meilisearch.com | sh
# Launch Meilisearch without key
./meilisearch
# Or
meilisearch
# Launch Meilisearch with key in the .env.example
meilisearch --master-key joVaZyaMWrqrO8OXEyTPxpvE8kY_gjLf6FTq1t9chR8
php artisan scout:import "App\Models\Post"
php artisan scout:sync-index-settings
Request:
GET http://localhost:8000/api/search?query=dolor&order_by=category_id,desc
Response:
{
"data": {
"current_page": 1,
"data": [
{
"id": 238,
"title": "Voluptatibus voluptate ea ipsam.",
"slug": "voluptatibus-voluptate-ea-ipsam",
"content": "Rem et optio voluptas omnis aspernatur. Reiciendis debitis ea recusandae dolorem ad saepe. Voluptates et possimus animi at. Corporis a sit ipsum amet eius laudantium. Omnis sunt atque perspiciatis in et qui.",
"published": 1,
"category_id": 3,
"created_at": "2023-07-06T02:55:05.000000Z",
"updated_at": "2023-07-06T02:55:05.000000Z",
"category": {
"id": 3,
"name": "error",
"slug": "error",
"created_at": "2023-07-06T02:55:04.000000Z",
"updated_at": "2023-07-06T02:55:04.000000Z"
}
},
// ...
},
"status": 200
}
Please check the following article:
https://fajarwz.com/blog/simple-and-advanced-search-with-laravel-scout-and-meilisearch/#hey-why-isnt-the-string-ordering-in-the-expected-order
Request:
POST http://localhost:8000/api/posts
data:
{
"title": "zulfikar",
"content": "zulfikar is a software engineer",
"published": 1,
"category_id": 7
}
Response:
{
"data": {
"title": "zulfikar",
"slug": "zulfikar-1688607259",
"content": "zulfikar is a software engineer",
"published": 1,
"category_id": 7,
"updated_at": "2023-07-06T01:34:19.000000Z",
"created_at": "2023-07-06T01:34:19.000000Z",
"id": 1011
},
"status": 200
}