title: Laravel - must return a relationship instance exception handling
body: <p>I would like to display employee department based on this relation</p>
  
  <p>here is the JobHistory table schema</p>
  
  <pre><code>    Schema::create('JobHistories', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;integer('employees_id');
          $table-&gt;integer('Jobs_id');
          $table-&gt;integer('Departments_id');
          $table-&gt;date('start_date');
          $table-&gt;timestamps();
      });
  </code></pre>
  
  <p>here is the employee model</p>
  
  <pre><code>    public function jobs(){
          return $this-&gt;hasMany(JobHistory::class,'employees_id','id');
      }
  
      public function getDepartment()
      {
         $dep = JobHistory::where('employees_id', $this-&gt;id)-&gt;orderBy('start_date', 'desc')-&gt;first();
  
         return ($dep) ? $dep-&gt;department() : '';
  
      }
  </code></pre>
  
  <p>here is function on JobHistory Model</p>
  
  <pre><code>    public function department()
  {
      return $this-&gt;belongsTo(Department::class, 'Departments_id', 'id');
  }
  </code></pre>
  
  <p>And finally I want to display it on view like this:</p>
  
  <pre><code>    @foreach($employee as $row)
       &lt;tr&gt;
         &lt;td&gt;{{$row-&gt;name}}&lt;/td&gt;
         &lt;td&gt;
           {{$row-&gt;getDepartment-&gt;name or '-'}}
         &lt;/td&gt;
       &lt;/tr&gt;
      @endforeach
  </code></pre>
  
  <p>The question is, how to handle exception if an employee does not have any job history yet? I have try using is_null(), empty() and isset() on blade validation. but nothing works.</p>