Laravel 5 simple search box using GET method

Laravel 5 simple search box using GET method

SHARE

First of all, I know there are many ways to do this, and this might not be the best way to do it.

So what we are going to do is to add a search box text field in the upper left side of our table. Definitely it will search for any records containing the word to search. The search box can be reuse in other index as well to make tidy codes.

First Step: View

This is the search box (please never mind the add link, you can remove it if you want). Here, we create a form that will direct to officesController@index. The method we use is GET. The role is the variable you will use in your URI to put the search parameter.

You may put this code in a separate blade and reuse it with other view, OR you can just directly add it in the view below which is the index.

Since we will be going to incorporate our search box in the index.blade.php we will going to add it to it.

 

If you want to reuse our search box to other pages, you can do something like below, and save it as search.blade.php

We converted our text parameters into variables, then in every index.blade.php we include it, and add some variables that should be same name to the variable of the search box. So in your index, include the following code.

This will reuse the search.blade.php by including it to every index.blade.php you have.

Note: This may not exact solution for nested URI segments.

In this stage we will test our search and you should get something like below.

the search box4

here, we searched for an office name BAC. Since we are using GET method, you should have the ?search=BAC params in your URL.

Prev1 / 2

SHARE
Programmer, Database Designer and Administrator for Web Application. Who loves to read and write interesting topics.