mardi 24 novembre 2015

1:1 relationships in Laravel returns Undefined property

I keep getting this error in Laravel 5 when working on a 1:1 database relationship:

Undefined property: Illuminate\Database\Eloquent\Collection::$owner

In my controller i have method "stuff". When i return $stuff i get:

[{"id":4,"demoId":2,"slug":"loremipsum","languageId":1,"countryId":1,"created_at":"-0001-11-30 00:00:00","updated_at":"-0001-11-30 00:00:00"}]

The relationship is on "demoId".

In my controller i have this:

public function owner(){
    return $this->belongsTo('App\Demotable2');
}

I'm using this code, that gives an error:

$routine = $stuff->owner->get()->toArray();

I expect to get the info in the demotable2. What do i do wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire