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.

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-10">
            <form action="">
                <h2>Search content in database using Laravel</h2>
                <div class="form-group">
                    <input type="text" name="q" placeholder="Find or Search Members...!" class="form-control"/>
                    <input type="submit" class="btn btn-primary" value="Search"/>
        <div class="col-md-10">
            <table class="table">
                @foreach($data as $Member)

            {{ $data->links() }}

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

Also Read This ๐Ÿ‘‰   User Profile Edit Script Update Script Laravel 7/6

Route::get("/search",'[email protected]');

Run Paginated data with Search functionality in Laravel Table

php artisan serve


Pagination for search results laravel
Pagination for search results laravel