title: Laravel conditions in Controller where clause
body: <p>I'm trying to build a query based on URL parameters.  When the Controller is loaded I need to check which parameters have been provided and build a query from them.  It's working with static values, but isn't working with conditional statements.  Is my laravel syntax correct?</p>
  
  <p>
  
  <pre><code>class OrdenesController extends BaseController {
  
  public function showOrdenes($action)
  {
    $my_id = Auth::user()-&gt;id;
    $my_cod = Auth::user()-&gt;codprov;
  
    switch ($action) 
    {
      case 'list':
        $rows = DB::table('ordens')-&gt;count();
        if(Input::get("jtSorting"))
        {
         $search = explode(" ", Input::get("jtSorting"));            
         $numorden= Input::get("nro_orden");
         $filtros =explode(" ", $filtros);
  
         $data = DB::table("ordens")
          -&gt;select(array('*', DB::raw('SUM(cant_pend) as cant_pend'), DB::raw('SUM(importe) as importe')))
          -&gt;where('cod_prov', '=', $my_cod)
  
          -&gt;where('nro_orden', '=', $numorden)///work
  
          ---------- ////no work
          if (Input::has('nro_orden')) {
             -&gt;where('nro_orden', '=', $numorden)
          }
          ---------- /// no work
  
          -&gt;groupBy('nro_orden')
          -&gt;skip(Input::get("jtStartIndex"))
          -&gt;take(Input::get("jtPageSize"))
          -&gt;orderBy($search[0], $search[1])
          -&gt;get();
        }
        return Response::json(
          array(
            "Result"      =&gt;    "OK",
            "TotalRecordCount"  =&gt;    $rows,
            "Records"     =&gt;    $data
          )
        );
        break;
  
     };  
    }    
  }
  </code></pre>