I am doing some exercises, but there is one where I can not understand why it is not working when I make another name in the method. I have a method in Model Location
, where it does relationships
of OneToOne
.
When I call the method with the simple name it works, more when I call the method with the compound name it from null
.
Model Location
public function countryInverso()
{
return $this->belongsTo(Country::class);
}
OneToOne Controller
public function umPraUmReverso()
{
$location = Location::where('latitude', 54)->get()->first();
$country = $location->countryInverso;
dd($country);
}
This way returns dd()
as null
Now if I put it this way
Model Location
public function country()
{
return $this->belongsTo(Country::class);
}
OneToOne Controller
public function umPraUmReverso()
{
$location = Location::where('latitude', 54)->get()->first();
$country = $location->country;
dd($country);
}
In this last way it returns to me the data, because, with the name in the method countryInverso
does not work and only with the name country
it works?