Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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'));
    }


Source by programmierfrage.com #
 
PREVIOUS NEXT
Tagged: #laravel #search #pagination
ADD COMMENT
Topic
Name
9+6 =