title: Translate from CodeIgniter Active Record model to Laravel Eloquent
body: <p>I am a CodeIgniter trying to adopt Laravel, however, I have been having a lot of problems understanding how to use Eloquent.</p>
  
  <p>I suspect that if I could figure out how to translate some of my CodeIgniter Model methods to Laravel Eloquent I might be able to get on better. Hopefully, this will help others with the same problem.</p>
  
  <p>Could anybody please rewrite the following from CodeIgniter to Eloquent:</p>
  
  <pre><code>public function get_products($product_id = NULL, $category_id = NULL, $limit = NULL)
  {
      $this-&gt;db-&gt;select('*, product.id AS product_id');
      $this-&gt;db-&gt;from('product');
      $this-&gt;db-&gt;join('product_unit', 'product.source_unit_id = product_unit.id', 'left');
      $this-&gt;db-&gt;join('stock_levels', 'product.stock_level_id = stock_levels.id', 'left');
      $this-&gt;db-&gt;join('categories', 'product.category_id = categories.cat_id', 'left');
      if(isset($product_id)) {
          $this-&gt;db-&gt;where('product.id', $product_id);
      }
      if(isset($category_id)) {
          $this-&gt;db-&gt;where('product.category_id', $category_id);
      }
      if(isset($limit)) {
          $this-&gt;db-&gt;limit($limit);
      }
      #$this-&gt;db-&gt;order_by('categories.cat_name', 'ASC');
      $this-&gt;db-&gt;order_by('categories.cat_name', 'ASC');
      $this-&gt;db-&gt;order_by('product.name', 'ASC');
      $query = $this-&gt;db-&gt;get();
      return $query-&gt;result_array();
  }
  </code></pre>