Laravel Scout Algolia Search Example
https://www.itsolutionstuff.com/post/laravel-scout-algolia-search-exampleexample.html
Last updated
https://www.itsolutionstuff.com/post/laravel-scout-algolia-search-exampleexample.html
Last updated
By Hardik Savani January 12, 2020 Category : LaravelPlayUnmuteLoaded: 1.15%FullscreenIn this tutorial, i will give you step by step example of laravel scout full text search. i will show you how to create full text search using laravel scout algolia.
You can follow this example for scout full text search in laravel 6, laravel 7, laravel 8 and laravel 9 project.
Laravel provide us several new feature and introduce new packages. Laravel provide Scout Package for full text search from your Model. If you require to add full text search function in your laravel application then you have to choose scout package for to do.
In this example i going to explain step by step, so you can simple understand and use it in your laravel project. In this tutorial i give from scratch so let's follow simple few step and implement full text search function in your laravel application.
Preview:
Step 1: Install Laravel Application
In this step, if you haven't laravel application setup then we have to get fresh laravel application. So run bellow command and get clean fresh laravel application.
Step 2: Install Packages
In this step we have to add two packages, there are listed bellow:
1)laravel/scout
2)algolia/algoliasearch-client-php
Ok, so first we will install "laravel/scout" package by following command:
Now we have to publish configure file by using bellow command, After this command run, you will find new file scout.php in config folder and we will set configure details on it, so let's run bellow command:
Now we need to set configuration queue is true in your env file:
.env
Ok, now we have to install package for "algolia", so let's run bellow command:
Read Also: Laravel - How to get current URL in controller or view?
Step 3: Package Configuration
Ok, now we have to set id and secret of algolia, so first you have to create new account in algolia.com. So if you haven't account on algolia.com site then click here and create new account : algolia.com.
Ok, after login we have to get application id and secret so click here and open that web page: GET APP ID and SECRET. After open you will see bellow screen and copy your id and secret.
Ok, now open your .env file and paste id and secret like as bellow:
.env
Step 4: Create Item Table and Model
In this step we have to create migration for items table using Laravel php artisan command, so first fire bellow command:
After this command you will find one file in following path database/migrations and you have to put bellow code in your migration file for create items table.
After create "items" table you should create Item model for items, so first create file in this path app/Item.php and put bellow content in item.php file:
app/Item.php
Step 5: Add New Route
In this is step we need to create routes for add new items and listing. so open your routes/web.php file and add following route.
routes/web.php
Step 6: Create Controller
In this step, now we should create new controller as ItemSearchController in this path app/Http/Controllers/ItemSearchController.php. this controller will manage all listing items and add new item request and return response, so put bellow content in controller file:
app/Http/Controllers/ItemSearchController.php
Step 7: Create View
In Last step, let's create item-search.blade.php(resources/views/item-search.blade.php) for layout and we will write design code here and put following code:
resources/views/item-search.blade.php
Ok, now we are ready to run this example so quick run by following command:
Now open your browser and run bellow link:
If you have already added few records on your table then you can index that records by run following command:
Read Also: Laravel Typeahead Search Tutorial
Maybe it can help you.....