title: Groupby on relation laravel
body: <p>Hey i have three table like this</p>
  
  <pre><code>--table plan--
  id
  name
  ....
  
  ----table letter---
  id
  plan_id
  ....
  
  ---table person----
  id
  plan_id
  name
  .....
  </code></pre>
  
  <p>Model i have :</p>
  
  <pre><code>---Model plan---
  class plan extends Model
  {
      protected $table = 'plan';
      public function letter(){
         return $this-&gt;hasOne('App\letter');
      }
      public function person(){
         return $this-&gt;hasMany('App\person');
      }
  }
  --Model person--
  class person extends Model
  {
      public function plan(){
         return $this-&gt;belongsTo('App\plan');
      }
  }
  
  --Model letter--
  class letter extends Model
  {
      public function plan(){
         return $this-&gt;belongsTo('App\plan');
      }
  }
  </code></pre>
  
  <p>And in controller i write code like this : </p>
  
  <pre><code>$letter = letter::find($id) // $id from url parameter and it's work
  return view('letter',['letter' =&gt; $letter]);
  </code></pre>
  
  <p>Nah in view i wanna acces person name from letter model as distinct , so i write code like this</p>
  
  <pre><code>{{ @foreach ($letter-&gt;plan()-&gt;person()-&gt;groupBy('name')-&gt;get) as $person }}
  </code></pre>
  
  <p>but it return error like this :
  Call to undefined method Illuminate\Database\Query\Builder::person()</p>
  
  <p>Where is my mistake(s)?</p>