Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kisaw88's avatar

How to add search functionality in a table in laravel

hello i want to add a search functionality in a table , because the table contains too much data, and also pages, so i want to give the user the ability to search through the table to easily find the searched data, i'am not familliar with VueJS so does elequent provide any solution ?

0 likes
5 replies
kisaw88's avatar

@CHRISPAGE1 - but the problem i see , is that does the search in the backend, how do i display i search bar in the blade ? like when i want to do users table pagination i can use paginate() in the controller then i can use

      {{$userss->links()}}
Sabbir345's avatar

Step 1

< input type="text" v-model="search" class="form-control " >

< button class="btn btn-primary">

Step 2

export default {

data () {

  return {
    alldata:[],
    search:'',
    perPage: 20,
    totalData: 0,
  }
},
watch: {
    search() {
      if (this.search.length != 0) {
        this.TableData();
      }
    }
},

Step 3

NB: make a method TableData

     TableData(nextPage = null) {
      

       let url = `http://127.0.0.1:8000/searchl?per_page=${this.perPage}`;

        if(nextPage) {
          url += `&page=${nextPage}`;
         
        }
        if (this.search.length) {
            url += `&search=${this.search}`;
        }
       

Then call axios

step 4

      axios.get(url)
chrispage1's avatar

@KISAW88 - Search form in blade can be (assuming your route to your controller method is /users and you have a POST route setup) -

<form method="POST" action="/users">
    @csrf
    <input type="search" placeholder="Search here" />
    <button type="submit">Search</button>
</form>

Then on your controller method you do the following (with a Scout plugin / Laravel TNTSearch installed) -

if ($request->has('search')) {
    $users = User::search($request->input('search'));
} else {
    $users = User::query();
}

return view('users', ['users' => $users->paginate()]);           

Please or to participate in this conversation.