Dynamic properties for relations return null

Published 9 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.

Dry7
Dry7
9 months ago (151,880 XP)

@SevenOutman what returns

$user->primary_receiver

?

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