11 months ago

Eloquent query error

Posted 11 months ago by leonvr

I have the following code in a controller:

$wishlist = $invitation->wishlist;

This causes the following error

Undefined property: stdClass::$wishlist

$invitation is correct at that time (notice wishlist_id):

{#511 ▼
  +"id": 45
  +"user_host_id": 14
  +"wishlist_id": 21
  +"user_famvr_id": 19
  +"meta_user_type": "fvanoniem"
  +"active": 1
  +"accepted": 1
  +"created_at": "2019-06-13 16:44:14"
  +"updated_at": "2019-06-13 16:44:14"

In my Invitation class:

    public function wishlist()
        return $this->belongsTo(Wishlist::class);

In this case I am expecting the $wishlist to be filled with the wishlist-record with id=21, but I get an error. What am I doing wrong?

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