title: Eloquent query so slow in Laravel
body: <p>I'm doing an application in Laravel 5.3.19, the thing is, I'm doing a query with Eloquent but it is SO slow, I read some forums and seems like I'm doing something wrong, I tried doing this query in the console with the command <code>php artisan tinker</code> and the query work perfectly, the problem is when I log into the URL that I created in the <code>routes/web.php</code> from my browser, the page just load indefinitely and sometimes It gives to me a timeout error. Someone knows what could be the problem? </p>
  
  <p>here are my files:</p>
  
  <ul>
  <li>routes/web.php</li>
  </ul>
  
  <p></p>
  
  <pre><code>Route::get('/area_products/listProductsByArea/{area}','AreaProductController@orderProductsListByArea');    
  </code></pre>
  
  
  
  <ul>
  <li>Http/controllers/AreaProductController.php (Controller)</li>
  </ul>
  
  <pre class="lang-php prettyprint-override"><code>public function orderProductsListByArea($area){
      $array_products = [];
      $products = AreaProduct::where('area_id', $area)-&gt;get();
      foreach ($products as $data) {
          $product = [
              'id' =&gt; $data-&gt;id,
              'price' =&gt; $data-&gt;price,
              'product_id' =&gt; $data-&gt;product-&gt;id,
              'product_name' =&gt; $data-&gt;product-&gt;name,
              'product_category' =&gt; $data-&gt;product-&gt;category-&gt;name,
              'product_reference' =&gt; $data-&gt;product-&gt;reference,
              'product_code' =&gt; $data-&gt;product-&gt;code,
              'area_id' =&gt; $data-&gt;area_id
          ];
          array_push($array_products, $product);
      }
  }    
  </code></pre>
  
  <ul>
  <li>Http/AreaProduct.php (Model)</li>
  </ul>
  
  
  
  <pre><code>namespace App;
  use Illuminate\Database\Eloquent\Model;
  class AreaProduct extends Model{
      public $table = "products_area";
      public function product(){
          return $this-&gt;belongsTo('App\Product');
      }
      public function area(){
          return $this-&gt;belongsTo('App\Area');
      }
  }
  </code></pre>
  
  
  
  <p>Note: This query should return near to 700 results, I noticed the problem is produced when I'm doing the relations stuff like <code>'product_name' =&gt; $data-&gt;product-&gt;name</code>. Am I doing something wrong? </p>
  
  <p>Thanks for your help.</p>