title: Laravel Eloquent belongsTo relationship is not working
body: <p>I'm trying to create a relationship between two tables using Eloquent <code>belongsTo</code> but it doesn't seem to work.</p>
  
  <p>the two tables are documents and departments , each document belongs to one department.</p>
  
  <p>documents </p>
  
  <pre><code>id INT
  department INT
  </code></pre>
  
  <p>departments</p>
  
  <pre><code>id INT
  name varchar(255)
  </code></pre>
  
  <p>this is the function that defines the relationship</p>
  
  <pre><code>public function department(){
      // department: foreign key
      // id : departments table primary key
      return $this-&gt;belongsTo('\App\Department' , 'department' , 'id');
  }
  </code></pre>
  
  <p>and this is the accessor function </p>
  
  <pre><code>public function getDepartmentAttribute(){
      return $this-&gt;department()-&gt;first()-&gt;name;
  }
  </code></pre>
  
  <p>it returns the following error message: <code>Undefined property: App\AjaxSearch::$department</code></p>