title: Trying to get property of non-object in View in Laravel
body: <p>I'm new to Laravel and I think I'm doing something wrong when trying to render data passed to views.</p>
  
  <p>Here's my route, where I build a simple array:</p>
  
  <pre><code>Route::get('/', function () {
      $data = [];
  
      foreach(App\User::all() as $user) {
          foreach($user-&gt;orders as $order) {
              foreach ($order-&gt;sub_orders as $sub_order) {
                  $data[] = 
                      [
                          'customer_id' =&gt; $user-&gt;id, 
                          'customer_name' =&gt; $user-&gt;name, 
                          'city' =&gt; $user-&gt;city, 
                          'order_id' =&gt; $order-&gt;id, 
                          'order_date' =&gt; $order-&gt;created_at-&gt;format('Y-m-d H:i:s'),
                          'sub_order_id' =&gt; $sub_order-&gt;id,
                          'item_name' =&gt; $sub_order-&gt;item-&gt;name,
                          'quantity' =&gt; $sub_order-&gt;quantity,
                          'unit_price' =&gt; $sub_order-&gt;item-&gt;unit_price,
                          'total_price' =&gt; $sub_order-&gt;item-&gt;unit_price * $sub_order-&gt;quantity,
                          'delivery_date' =&gt; $sub_order-&gt;delivery_date,
                          'delivery_status' =&gt; $sub_order-&gt;delivery_status
                      ];
              }
          }
      }
  
      return view('welcome', ["data" =&gt; $data]);
  });
  </code></pre>
  
  <p>And here's how I'm attempting it on the view side:</p>
  
  <pre><code>@foreach ($data as $row)
    &lt;tr&gt;
      &lt;td&gt; {{ $row-&gt;customer_id }} &lt;/td&gt;
    &lt;/tr&gt;
  @endforeach
  </code></pre>
  
  <p>This gives me the error <code>Trying to get property of non-object</code> on the line <code>&lt;td&gt; {{ $row-&gt;customer_id }} &lt;/td&gt;</code>. I don't understand what I'm doing wrong. :| </p>
  
  <p>Also, is there any way to <code>dd</code> or <code>var_dump</code> the data received in the view?</p>