Luis Lopez
Luis Lopez

Reputation: 1277

Adjust a width and height to an image (Model-Blade) Laravel

I'm trying to adjust an image with a specific width and height, but it's echoed with blade and I don't know how to.

This is the code:

In blade:

<li style="text-align:center"><strong>Fotos:</strong>
    @forelse($publication->photos()->get() as $key => $photo)
    <div>
        {{ $photo->image }}
    </div>
    @empty
    EL usuario no ha agregado fotos
    @endforelse
</li>

In the model the method photos():

public function photos()
{
    return $this->hasMany('BookPublicationPhoto', 'published_book_id');
}

This is the result (Photo out of page width)

https://i.sstatic.net/mgcCZ.jpg

Have any idea of how I could proceed?

Solution

I had other model which has the imagemethod so I just added the width and height:

public function getImageAttribute()
{
    return HTML::image('img/publication/'.$this->published_book_id.'/'.$this->image_file_name, '-', ['class' => 'thumb', 'width' => 150, 'height' => 200]);
}

Upvotes: 2

Views: 2201

Answers (1)

Bhaumik Pandhi
Bhaumik Pandhi

Reputation: 2673

You can install LaravelCollective package, and use below code to set height, width.

{{ HTML::image('image_url','image alt title',['width'=>'100','height'=>'200']) }}

Upvotes: 2

Related Questions