vendredi 22 janvier 2016

Laravel — How to get string value from object via model method?

I have model House with relation hasMany HousePhotos. I try get link to main photo from table house_photos.

class House extends Model
{

    public function photos(){

    return $this->hasMany('app\HousePhoto');

    }

    public function get_main_photo(){

    return $this->photos()->where('main', true);

    }

}

Controller:

$house=House::find(1);

In View i use

{{$house->main_photo()->link}} 

and got error.

When i use

{{$house->main_photo()}} 

i got object. How to get string value of link to photo?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1nDbI3E
via IFTTT

Aucun commentaire:

Enregistrer un commentaire