Dynamic properties for relations return null

Posted 11 months ago by SevenOutman

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.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.