title: I have a problem with try to get a property of a column in Laravel
body: <p>I already know that the problem with this question that I will explain is similar to these other questions.</p>
  
  <p><a href="https://stackoverflow.com/questions/32547972/trying-to-get-property-of-non-object">Trying to get property of non-object</a></p>
  
  <p><a href="https://stackoverflow.com/questions/51022315/trying-to-get-property-of-non-object-in-laravel-5-4">Trying to get property of non-object in laravel 5.4</a></p>
  
  <p><a href="https://stackoverflow.com/questions/46351893/trying-to-get-property-of-non-object-in-laravel-5-5">Trying to get property of non-object in laravel 5.5</a></p>
  
  <p>But my problem is not the exactly the same problem of those questions or a another similar question.</p>
  
  <p>I have a website about Sale of Cars where I show a table with all customers and the number of cars that each customer has bought, when I click on the button 'See more details...' the web page redirects to another web page that show more details about the selected customer.</p>
  
  <p>On that webpage I have another table that shows the number of cars, the date, the model and the car's brand, that the customer has purchased, and a button that you can add a new car that the customer has bought.</p>
  
  <blockquote>
    <p><em>NOTE:I enter in this website as an ADMIN.</em></p>
  </blockquote>
  
  <p>When I click on this button to add new cars. I get this error. </p>
  
  <blockquote>
    <p>ErrorException (E_ERROR)
     Trying to get property 'id' of non-object (View: C:\xampp\htdocs\car- 
     shopping\resources\views\CarShop\ShowCustomerCarsDetails.blade.php)</p>
  </blockquote>
  
  <p>The line of code that this message of mistake emphasizes is:</p>
  
  <pre><code>&lt;td&gt;{{$customer-&gt;id}}&lt;/td&gt;
  </code></pre>
  
  <p>This is the Table of customer details that appears after I clicked the button <em>(says: see more details...)</em> on the previous page. Before the page ShowCustomerCarDetails.blade.php.</p>
  
  <pre><code>&lt;!--ShowCustomerCarDetails.blade.php--&gt;
  
  &lt;tbody&gt; 
    &lt;tr&gt;
  
  
      &lt;td&gt;{{$customer-&gt;id}}&lt;/td&gt; &lt;!--THIS LINE--&gt;
  
  
      &lt;td&gt;{{$customer-&gt;name}}&lt;/td&gt;
      &lt;td&gt;{{$customer-&gt;address}}&lt;/td&gt;
      &lt;td&gt;{{$customer-&gt;phoneNumber}}&lt;/td&gt;
  
          @if($car-&gt;id == $customer-&gt;car_id)
              &lt;td&gt;{{$car-&gt;model}}&lt;/td&gt;
          @endif           
      &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <blockquote>
    <p><em>NOTE:</em> The previous page of <strong>'ShowCustomerCarDetails.blade.php'</strong> is called, <strong>'ShowCustomersAndCars_index.blade.php'</strong> On this webpage I have a table that shows all customers and the number of cars that they have bought, is in this page that I have a button called <em>'See more details...'</em> that redirect to <strong>'ShowCustomerCarDetails.blade.php'</strong>.</p>
  </blockquote>
  
  <p>And this is the body of the table car that the customer has bought.</p>
  
  <pre><code>&lt;!--At the end of the website 
  ShowCustomerCarDetails.blade.php --&gt;
  
  &lt;thead&gt;
    &lt;tr&gt;
       &lt;th&gt;CAR NAME&lt;/th&gt;
       &lt;th&gt;CAR MODEL&lt;/th&gt;
       &lt;th&gt;CAR PRICE&lt;/th&gt;
       &lt;th&gt;CAR YEAR&lt;/th&gt;
       &lt;th&gt;PURCHASE DATE&lt;/th&gt;
       &lt;th&gt;OWNER&lt;/th&gt;
      &lt;/tr&gt;
  
  &lt;/thead&gt;
  
  &lt;tbody&gt;
      @foreach($date as $carDateBuy)
          @if($customer-&gt;id == $carDateBuy-&gt;customer_id)
              &lt;tr&gt;
                  &lt;td&gt;{{$car-&gt;name}}&lt;/td&gt;             
                  &lt;td&gt;{{$car-&gt;model}}&lt;/td&gt;
                  &lt;td&gt;{{$car-&gt;price}}&lt;/td&gt;
                  &lt;td&gt;{{$car-&gt;year}}&lt;/td&gt;
                  &lt;td&gt;{{$carDateBuy-&gt;date}}&lt;/td&gt;
                  &lt;td&gt;{{$carDateBuy-&gt;customer_name}}&lt;/td&gt;
              &lt;/tr&gt;
          @endif
      @endforeach
  &lt;/tbody&gt;
  </code></pre>
  
  <blockquote>
    <p><em>NOTE: The Table dates, it fills automatically with customer's information when a customer buys a car.</em></p>
  </blockquote>
  
  <p>And the button to add new cars in the same web page.</p>
  
  <pre><code>&lt;div&gt;
    &lt;a href="{{route('NewCars')}}"&gt;
      &lt;input type="button" name="AddCars" value="ADD NEW CAR"&gt;
    &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And the route in <strong>web.php</strong></p>
  
  <pre><code>Route::get('ListCustomersCar/NewCars',['as' =&gt; 'NewCars', 'uses' =&gt; 'CustomerCarController@createNewCars']); 
  </code></pre>
  
  <p>The <strong>CustomerCarController</strong> method <code>createNewCars()</code>:</p>
  
  <pre><code>public function createNewCars(){
  
    return view('customer.NewCars');
  }
  </code></pre>
  
  <p>For more details I add the tables and his relations:</p>
  
  <p><a href="https://i.stack.imgur.com/AZMWP.png" rel="nofollow noreferrer">Picture1_Car-Customer</a></p>
  
  <p><a href="https://i.stack.imgur.com/yjlFP.png" rel="nofollow noreferrer">Picture2_Customer-Date1</a></p>
  
  <p><a href="https://i.stack.imgur.com/Bs7Eq.png" rel="nofollow noreferrer">Picture3_Customer-Date2</a></p>
  
  <p>What I'm doing wrong in my website? If I'm missing something, I will update this question. Thanks!</p>