Support the ongoing development of Laravel.io →
posted 7 years ago
Database
Last updated 2 years ago.
0

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');
}
0

your status and record relationship is not one to many, it's one to one,

0
Solution

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!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

gezzeg gezzeg Joined 31 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.