title: How to solve Error "Trying to get property of non-object" on Laravel
body: <p>I am trying to get the list from the Database, but the page showed the error "Trying to get property of non-object" please help me, I got stacked on this, here the code make error: <code>$status = ($employee-&gt;Profile-&gt;date_of_leaving == null) ? '&lt;span class="label label-success"&gt;active&lt;/span&gt;' : '&lt;span class="label label-danger"&gt;in-active&lt;/span&gt;';</code></p>
  
  <p>and below is the extended code of the file it self.</p>
  
  <pre><code>        foreach ($employees as $employee){
          $designation = $employee-&gt;Designation;
          $status = ($employee-&gt;Profile-&gt;date_of_leaving == null) ? '&lt;span class="label label-success"&gt;active&lt;/span&gt;' : '&lt;span class="label label-danger"&gt;in-active&lt;/span&gt;';
          $linkToEdit = "&lt;a href='employee/$employee-&gt;id/edit' class='DTTT_button_small'&gt; &lt;i class='fa fa-edit'&gt;&lt;/i&gt;&lt;/a&gt;";
          $linkToDelete = "&lt;a href='employee/$employee-&gt;id/delete/$token' class='DTTT_button_small alert_delete'&gt; &lt;i class='fa fa-trash-o'&gt;&lt;/i&gt;&lt;/a&gt;";
          $linkToView = "&lt;a href='employee/$employee-&gt;id' class='DTTT_button_small'&gt; &lt;i class='fa fa-share'&gt;&lt;/i&gt;&lt;/a&gt;";
          $Option = "$linkToView $linkToEdit $linkToDelete";
          $col_data[] = array(
                  ($employee-&gt;Profile-&gt;employee_code != '') ? $employee-&gt;Profile-&gt;employee_code : 'Not assigned' ,
                  $employee-&gt;first_name,
                  $employee-&gt;last_name,
                  $employee-&gt;username,
                  $employee-&gt;email,
                  $designation-&gt;designation,
                  $status,
                  $Option);    
          }
  </code></pre>