Laravel 5 – elasticsearch with pagination example
In this post we will give you information about Laravel 5 – elasticsearch with pagination example. Hear we will give you detail about Laravel 5 – elasticsearch with pagination exampleAnd how to use it also give you demo for it if it is necessary.
If you haven’t install elasticsearch and you don’t know how to install elasticsearch in laravel then you have to see first bellow link, in this link you can set up elasticsearch from scratch like install package, use with laravel model etc. :
How to use elasticsearch from scratch in laravel 5?
.
After finish step of above link, we can make elasticsearch with pagination view using laravel pagination eloquent. after impletement this example we could find layout like as bellow link.
Preview
Ok, we have to just few changes and we can make pagination in our laravel application. so first open ItemSearchController.php controller and replace index method this way.
app/Http/Controllers/ItemSearchController.php
....
/**
* Display a listing of the resource.
*
* @return IlluminateHttpResponse
*/
public function index(Request $request)
{
if($request->has('search')){
$page = $request->input('page', 1);
$paginate = 3;
$items = Item::searchByQuery(['match' => ['title' => $request->input('search')]], null, null, $paginate, $page);
$offSet = ($page * $paginate) - $paginate;
$itemsForCurrentPage = $items->toArray();
$items = new IlluminatePaginationLengthAwarePaginator($itemsForCurrentPage, $items->totalHits(), $paginate, $page);
$items->setPath('ItemSearch');
}
return view('ItemSearch',compact('items'));
}
....
Ok, at last we have to just render pagination view using laravel pagination eloquent in blade file. so open ItemSearch.blade.php file and change this:
ItemSearch.blade.php
.....
<div >
@if(!empty($items))
@foreach($items as $key => $value)
<h3 >{{ $value['title'] }}</h3>
<p>{{ $value['description'] }}</p>
@endforeach
{!! $items->appends(Input::all())->render() !!}
@endif
</div>
....
Try this one……
Hope this code and post will helped you for implement Laravel 5 – elasticsearch with pagination example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs