Posted inJavaScript / jQuery / Laravel / Mysql / php

laravel pagination with search Filter Best Example

laravel pagination with search: I am going to use Search Functionality with Advance Pagination within the CRUD (Create Table, Select, Insert, Update, Delete Table) table. Also Click for the CRUD (Create Table, Select, Insert, Update, Delete Table) Functionality TABLE.

Q : How to use Search Functionality with Pagination in Laravel PHP Framework?

laravel pagination with search

Information search like Categories, User, Member, Products, Contact in website using Laravel 8, Today, We are share best example simple pagination for search results in Laravel 8 app’s.

laravel pagination with search filter

if $id has some value it will include main conditions like as a “where(‘id’,’<',$id) else will return all"

$products = DB::table('products')
        ->when($id, function ($query, $id) {
            return $query->where('id','<',$id);

Okay, Now you can install laravel 8 latest version

Create Project for laravel pagination with search

composer create-project --prefer-dist laravel/laravel blog "8.0.*"

After then, you need make controller , you run command the following

# Make Controller in Laravel

php artisan make:controller FindController --resource

FindController.php file in directory App/Http/Controller, you open file and pass the following PHP Source code

public function index(Request $request)
        $search =  $request->input('q');
            $Members = Member::where(function ($query) use ($search){
                $query->where('name', 'like', '%'.$search.'%')
                    ->orWhere('email', 'like', '%'.$search.'%');
            $Members->appends(['q' => $search]);
            $Members = Member::paginate(2);
        return View('')->with('data',$Members);

If Member don’t search or find, you get data all Member in Member table
if Member search, you required using $search = $request->input(‘q’); get search data value, and then append youe some query string keyword $Members->appends([‘q’ => $search]);

Ok, you to resources/views/pages directory create search.blade.php file, aften then you pass the following code

Pagination View : Now in the view file search.blade.php.


Search content in database using Laravel

@foreach($data as $Member) @endforeach
{{$Member->ID}} {{$Member->name}} {{$Member->email}} {{$Member->created_at}} {{$Member->updated_at}}
{{ $data->links() }}

you can simply Configuration Route in laravel web application, open web.php in routes/web.php folder


Run Paginated data with Search functionality in Laravel Table

php artisan serve


Pagination for search results laravel
Pagination for search results laravel

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype