Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

Because you've got many TemplateImage for one Template, you need to iterate over the Temp object in your view. like this...

@foreach($temps->tempImage() as $tempImage)
    $tempImage->image
@endforeach

if you want to get the 1st result you can do this in your view

$temps->->tempImage()->first()->image

And in your TempImage, you 've got a fonction which have the same name in the Template model, in the templaimage, you get the template model so i think this function must be named temp() (its the inverse relation) :

class TemplateImage extends Model
{
public function temp ()
    {
        return $this->belongsTo('App\Models\Template', 'template_id');
    }
}
Last updated 6 years ago.

johnef liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

johnef johnef Joined 18 May 2016

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.