title: How to create functional search box to query data from a certain table?
body: <p>I would like to create functional <strong>search box</strong> to query data from a certain table. </p>
  
  <p><strong>Database Details:</strong> </p>
  
  <ul>
  <li>table name : inventories</li>
  <li>primary key : id</li>
  <li>unique index : sku </li>
  <li>size = 120, 000 rows</li>
  </ul>
  
  <hr>
  
  <p><strong>Search box Details :</strong> </p>
  
  <p>Blade/HTML</p>
  
  <pre><code>            {{ Form::open(array('action' =&gt; 'UrlController@query', 'method' =&gt; 'get')) }}
  
                  &lt;input autofocus name="search" id="search" placeholder="Enter Catalog # " type="text" /&gt;
  
                  &lt;span class="pull-right"&gt;
  
                      {{ Form::submit('Search', array('class' =&gt; 'btn btn-success btn-sm')) }}
  
                  &lt;/span&gt;
  
              {{ Form::close() }}
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/rW7kT.png" alt="enter image description here"></p>
  
  <p>As you can see, my search box name is <code>search</code></p>
  
  <hr>
  
  <p><strong>Controller Function :</strong> </p>
  
  <pre><code>public function query() {
  
          // grab GET parameters
          $search = Input::get('search');
  
          // apply search filter
          if ($search){
  
              //$inventories = Inventory::all(); # It's works if I do this
  
              $inventories = Inventory::where(function($inventories) use ($search){
                  $inventories-&gt;where('search', 'like', '%'.$search.'%');
              });
  
  
              return View::make('inventories.index')
              -&gt;with('inventories', $inventories);
          }else
  
          return View::make('inventories.index');
  
      }
  </code></pre>
  
  <hr>
  
  <p><strong>At the end :</strong> </p>
  
  <p>I couldn't get any result(s) to display.</p>
  
  <p>Did I do something wrong ? here : </p>
  
  <pre><code>$inventories = Inventory::where(function($inventories) use ($search){
                  $inventories-&gt;where('search', 'like', '%'.$search.'%');
              });
  </code></pre>
  
  <p>What is the most efficient way to accomplish this kind of task in Laravel ? </p>