title: How can I write if in query in laravel without breaking the chain and sequence
body: <p>I have the following query i need if statement in the query how can i do that. the following query gets the list of products based on manufacturers.
  If tried if after this query and then use get(); but that not work for me </p>
  
  <p>Query:</p>
  
  <pre><code>  $productsFeatured = Product::select('products.low_emitting_material_prerequisite_file',
          'manufacturers.phone','manufacturers.address','manufacturers.linkedin_url','manufacturers.city', 
          'products.specs_file','products.specs_file_url','products.low_emitting_material_credit_file', 
          'products.id', 'products.name', 'products.logo', 'products.manufacturer_id',
          'products.division_id', 'products.section_id', 'products.website', 'divisions.name as division_name', 'divisions.code as division_code',
          'sections.name as section_name', 'sections.code'   
           )
                  -&gt;whereIn('products.status', ['active'])
                  -&gt;where(function ($query) {
                      $query-&gt;where('products.low_emitting_material_prerequisite_file', '!=', '');
                  })
                  -&gt;where('users.user_type', 'manufacturer_paid')
                  -&gt;leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                  -&gt;leftJoin('sections', 'products.section_id', '=', 'sections.id')
                  -&gt;leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                  -&gt;join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                  -&gt;join('users', 'manufacturers.user_id', '=', 'users.id')
                  -&gt;orderBy('divisions.code', 'asc')
                  -&gt;orderBy('sections.code', 'asc')
                  -&gt;groupBy('products.id');
                  -&gt;get()
  </code></pre>
  
  <p>What I want</p>
  
  <pre><code>        $productsFeatured = Product::select('products.low_emitting_material_prerequisite_file',
          'manufacturers.phone','manufacturers.address','manufacturers.linkedin_url','manufacturers.city', 
          'products.specs_file','products.specs_file_url','products.low_emitting_material_credit_file', 
          'products.id', 'products.name', 'products.logo', 'products.manufacturer_id',
          'products.division_id', 'products.section_id', 'products.website', 'divisions.name as division_name', 'divisions.code as division_code',
          'sections.name as section_name', 'sections.code'   
           )
           $productsFeatured -&gt;whereIn('products.status', ['active'])
                  if($request-&gt;chps_approved ==  '63'){
                      $productsFeatured-&gt;where(function ($query) {
                          $query-&gt;where('products.low_emitting_material_prerequisite_file', '!=', '');
                      })
                  }
  
                  -&gt;where('users.user_type', 'manufacturer_paid')
                  -&gt;leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                  -&gt;leftJoin('sections', 'products.section_id', '=', 'sections.id')
                  -&gt;leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                  -&gt;join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                  -&gt;join('users', 'manufacturers.user_id', '=', 'users.id')
                  -&gt;orderBy('divisions.code', 'asc')
                  -&gt;orderBy('sections.code', 'asc')
                  -&gt;groupBy('products.id');
                   -&gt;get()
  </code></pre>
  
  <pre><code>
  </code></pre>