title: Laravel model to get specific piece of data
body: <p>I am trying to make a function that will help me get needed data quickly.</p>
  <p>With all the trials I have been able to get to the following</p>
  <p><strong>Tables</strong>:</p>
  <p>Users (id,name)</p>
  <p>Projects (id,name)</p>
  <p>User-Project (id, user_id, project_id, manager)  where manager is a boolean , there can only be one manager for each project (but employees can still see the project reason why we have a pivot table, manager = 0 for other normal users that can access that project)</p>
  <p>In the Project Model I have:</p>
  <pre><code>  public function Manager(){
      return $this-&gt;belongsToMany('App\User')-&gt;wherePivot('manager', true);
  }
  </code></pre>
  <p>In the View I have:</p>
  <pre><code> &lt;p&gt;&lt;strong&gt;Project Manager:&lt;/strong&gt; {{$project-&gt;manager}}&lt;/p&gt;
  </code></pre>
  <p>On the actual page I get:</p>
  <pre><code>Project Manager: [{&quot;id&quot;:4,&quot;name&quot;:&quot;Daniel Doe&quot;,&quot;email&quot;:&quot;danieldoe@hotmail.com&quot;,&quot;phone&quot;:&quot;70846556&quot;,&quot;email_verified_at&quot;:null,&quot;created_at&quot;:&quot;2020-12-20 21:05:50&quot;,&quot;updated_at&quot;:&quot;2020-12-20 21:05:50&quot;,&quot;pivot&quot;:{&quot;project_id&quot;:1,&quot;user_id&quot;:4,&quot;manager&quot;:1}}]
  </code></pre>
  <p>When I change the view to:</p>
  <pre><code>&lt;p&gt;&lt;strong&gt;Project Manager:&lt;/strong&gt; {{$project-&gt;manager[0]-&gt;name}}&lt;/p&gt;
  </code></pre>
  <p>I get:</p>
  <pre><code> Project Manager: Daniel Doe
  </code></pre>
  <p>This is what I actually want but I would like to do it from the model if possible. So I tried:</p>
  <pre><code>public function Manager(){
      return $this-&gt;belongsToMany('App\User')-&gt;wherePivot('manager', true)-&gt;first()-&gt;name;
  }
  </code></pre>
  <p>But I get the following error:</p>
  <pre><code>must return a relationship instance
  </code></pre>
  <p>Can this be done from the model's function?</p>