Displaying related data - why is it working?

Posted 2 years ago by ekrist1

I have defined a hasMany and belongsTo relationship. In my contact table I store the ID of the industry type (single id). If I eager load the relationship then I could use:

Industry: {{ $contact->lookup_industry_type->industry }} Output: Automobile Service

If I don´t eager load the relationship, then I´m successfully able to use this code in my blade file:

Industry: {{ $contact->lookup_industry_type['industry'] }} Output: Automobile Service

It seems like it lookup the industry field, but I haven´t found any documentation describing this behaviour. Is this an appropriate way to display related data which only stores one value?

Please sign in or create an account to participate in this conversation.