SevenOutman

Experience

50

0 Best Reply Awards

  • Member Since 9 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

28th November, 2017

SevenOutman started a new conversation Dynamic Properties For Relations Return Null • 9 months ago

Hey guys i'm using dynamic properties and got some problems

I have a User model and a Receiver model, Each User has a primary_receiver_id that points to a Receiver, And here's my relation

class User extends Model {
  public function primaryReceiver() {
    return $this->belongsTo(Receiver::class, 'primary_receiver_id');
  }
}

What went wrong was that when I use $user->primaryReceiver()->first(), I got a Receiver returned, But when I use $user->primaryReceiver on the same $user, even right next to the function call, like, I always got null.

What make things more weird is that no similar problem has occurred on any other relations. I have struggled with this but still can't figure out.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.