title: Laravel - ERROR: Trying to get property 'depthead' of non-object
body: <p>In my Laravel-5.8 blade that has this code:</p>
  
  <pre><code>@foreach($employees as $key =&gt; $employee)
                 &lt;li class="list-group-item"&gt;
                   &lt;b&gt;Line Manager:&lt;/b&gt; 
                   @if(!$employee-&gt;linemanager)
                    &lt;a class="float-right"&gt;N/A&lt;/a&gt;
                   @else
                   &lt;a class="float-right"&gt;{{ $employee-&gt;linemanager-&gt;fullName() ?? 'None' }}&lt;/a&gt;
                   @endif
                 &lt;/li&gt;  
                &lt;li class="list-group-item"&gt;
                  &lt;b&gt;HOD:&lt;/b&gt; 
                   @if(!$employee-&gt;department-&gt;depthead)
                    &lt;a class="float-right"&gt;N/A&lt;/a&gt;
                   @else
                   &lt;a class="float-right"&gt;{{isset($employee-&gt;department-&gt;depthead) ? $employee-&gt;department-&gt;depthead-&gt;first_name. ' ' .$employee-&gt;department-&gt;depthead-&gt;last_name : 'None'}}&lt;/a&gt;
                   @endif                                        
                &lt;/li&gt;  
  
  @endforeach 
  </code></pre>
  
  <p>and its pointing to this line:</p>
  
  <blockquote>
    <p>@if(!$employee->department->depthead)</p>
  </blockquote>
  
  <p>How do I resolve it?</p>
  
  <p>Thanks</p>