Search
 
SCRIPT & CODE EXAMPLE
 

PHP

pagination with search query in laravel

  {{ $products->appends($_GET)->links()}}
Comment

laravel pagination with search filter

// if $id has value it will include "where('id','<',$id) else will return all"
$wells = DB::table('well_s')
        ->when($id, function ($query, $id) {
            return $query->where('id','<',$id);
        })
        ->paginate(20);
Comment

Laravel 7 pagination with search filter

$tests = DB::table('view_tests')->whereIn('metric_id',$metricsIds)->paginate(4);

        $tests = $tests->filter(function ($item) use ($var) {
                    return false !== stristr($item->name, $var) || 
                    false !== stristr($item->section_name, $var) || 
                    false !== stristr($item->method, $var) || 
                    false !== stristr($item->limit, $var) || 
                    false !== stristr($item->accredited_detail, $var);

               return view('frontend.test_detailes',compact('tests'))->render();
Copy code
Comment

laravel 8 search with pagination

//web.php
    Route::get('contact-search',[ContactController::class,'search'])->name('contact.search');

//ui.blade.php
  <form action="{{route('contact.search')}}" method="get">
    <div class="me-2">
      <div class="input-group">
      <input type="text"  name="search" value="{{request('search')}}" class="form-control border border-primary" placeholder="Search" required>
      <button class="btn btn-outline-primary" type="submit">
      <i class="fa-solid fa-search"></i>
      </button>
      </div>
    </div>
  </form>
  {{ $contacts->appends(Request::all())->links() }}
  
//_Controller.php
public function search(IlluminateHttpRequest $request){
        $searchKey = $request->search;
        $contacts = Contact::where("name","LIKE","%$searchKey%")->orWhere("phone","LIKE","%$searchKey%")->paginate(5);
        return view('contact.index',compact('contacts'));
    }


Comment

laravel search and return record with pagination

//make sure that all your queries/builder has ->paginate and not a ->get() or 
//->first() then do {{ $var->links() }} in the blade

        if(empty($request->search)){
            $user = DB::table('users')->Paginate(15);
            return view('/users', ['user' => $user]);
        }else{
            $user = DB::table('users')->where('name', 'like', '%'. $request->search .'%')->Paginate(15);
            return view('/users', ['user' => $user]);
        }
Comment

Laravel 7 pagination with search filter

$tests = DB::table('view_tests')
    ->whereIn('metric_id',$metricsIds)
    ->where('name', '=', $var)
    ->paginate(4);
Copy code
Comment

PREVIOUS NEXT
Code Example
Php :: php best debugging functions 
Php :: program logic for second largest number in an array in php 
Php :: how to store file in public folder laravel 
Php :: The configuration file now needs a secret passphrase (blowfish_secret). 
Php :: php parse file 
Php :: how to get week start date in php 
Php :: php check if post file is empty 
Php :: how to retrieve image from database in php mysqli 
Php :: laravel collection put 
Php :: php ping 
Php :: AUTO_INCREMENT in laravel 
Php :: full month name php 
Php :: how validate the value of object in arraye in laravel 
Php :: arrow function in php 
Php :: wp get_posts return ids 
Php :: pdo close connection 
Php :: update laravel .env variables dynamically 
Php :: update many laravel 
Php :: update php version in laravel 
Php :: laravel guest blade 
Php :: Laravel: Validation unique on update 
Php :: php keep only digitts 
Php :: codeigniter order_by 
Php :: remove a specific element from an array php 
Php :: how to serve the port in php 
Php :: check if not empty blade engine 
Php :: php datetime add 1 weeek 
Php :: Laravel Retrieve All Session Data 
Php :: doctrine query builder order by multiple 
Php :: laravel destroy or delete 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =