mardi 27 décembre 2016

hasOne() not returning relationships because of method name

I am using laravel 5.3, I have listings table with hasOne relationship to cities table.

public function city()
{
    return $this->hasOne('App\City', 'id', 'city_id');
}

on my view



this cause error

Trying to get property of non-object

But when I change the method name to other than city,

public function foo()
{
    return $this->hasOne('App\City', 'id', 'city_id');
}

on my view



This one works.

What cause the problem with city method name? I have never problem with city method name in other projects.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hqtqr9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire