title: laravel- how do I retrieve name through the master table?
body: <p>I have three models that is:</p>
  
  <pre><code>User
  Order
  UserInfo
  </code></pre>
  
  <p>In User Model:</p>
  
  <pre><code>  /* Attribute to set primary user */
      protected $primaryKey = 'user_id';
  
       public function userInfo()
          {
              return $this-&gt;hasOne('App\Models\Users\UserInfo', 'user_id');
          }
  
        public function orders()
          {
  
              return $this-&gt;hasMany('App\Models\Orders\Order', 'user_id');
          }
  </code></pre>
  
  <p>In Orders model:</p>
  
  <pre><code>// Set table
  protected $table = 'orders';
  
  // Set timestamps
  public $timestamps = true;
  
  // Set primary key
  protected $primaryKey = 'order_id';
  
  // Set mass assignable columns
  protected $fillable = [];
  
  // Manys orders can belong to one user
  
  public function user()
  {
      return $this-&gt;belongsTo('App\Models\Users\User', 'user_id');
  }
  </code></pre>
  
  <p>In UserInfo model:</p>
  
  <pre><code> // Set table
      protected $table = 'user_infos';
  
      // Set timestamps
      public $timestamps = true;
  
      // Set primary key
      protected $primaryKey = 'user_id';
  
      // Set mass assignable columns
      protected $fillable = [];
  
  
  
  
      /**
       * Get the user info associated with the user.
       */
  
      public function user()
      {
  
          return $this-&gt;belongsTo('App\Models\Users\User', 'user_id');
      }
  </code></pre>
  
  <p>Each of their table has a common column called <code>user_id</code> where I will access through the Order model with the user id to match it with User model and retrieve the name from User Info.</p>
  
  <p>I tried to retrieve it with <code>Order::all()-&gt;user-&gt;userInfo-&gt;name-&gt;get()</code> but it says <code>Exception with message 'Property [user] does not exist on this collection instance.'</code></p>
  
  <p>What did I do wrong?</p>