Sunday, April 16, 2017

Laravel 5 Search in Multi attributes

I`m new to the laravel 5.4 and i need to create a multi attribute search.i can only do the search for a single attribute.but i cannot find out the right way to do so.

here is the search field i want. enter image description here

Here is the view related to it.

 <div class="form-group">
        <!-- <label>Select Your Institute</label> -->
        <label>Search By</label>
<select name="institute" id="institute">
  <option selected="selected" value="Trainee Id">Trainee Id</option>
    <option value="Trainee Name">Trainee Name</option>
  <label for="Search">Name</label>
</select>

<form action="search" method="post" class="form-inline">


       <input type="text" name="search" /><br>
       <input type="hidden" value="" name="_token" />
       <input type="submit" name="submit" value="Search">
       </form>


</div>

Here is the Controller which i need the modification for above view specially in drop down.

public function search_code(Request $request){
        $query = $request->search;
        $customers = DB::table('registerdetails')->where('id', 'LIKE',"%$query%")->get();
         return view('registeredusers.index')->with('customers',$customers);

        }

Can anyone suggest me the controller which i select from the drop down?



via Dasun

Advertisement