I think you want to use belongsTo:
https://laravel.com/docs/5.3/eloquent-relationships#one-to-many-inverse
function status()
{
return $this->belongsTo('App\Status');
}
your status and record relationship is not one to many, it's one to one,
Hi! Thanks for your feedback!
The solution is
class Record extends Model
{
public function status()
{
return $this->belongsTo('App\Status');
}
}
class Status extends Model
{
public function records()
{
return $this->hasMany('App\Record');
}
}
}
But it will throw "Trying to get property of non-object"
Just do like this
{{@$records->status->name}} or {{ $yourVar['value'] }}
I hope this will help others! Thanks!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community