【发布时间】:2017-09-28 23:58:50
【问题描述】:
我正在尝试调整具有特定宽度和高度的图像,但它与刀片相呼应,我不知道如何。
这是代码:
在刀片中:
<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>
在模型中的方法photos():
public function photos()
{
return $this->hasMany('BookPublicationPhoto', 'published_book_id');
}
这是结果(照片超出页面宽度)
知道我可以如何进行吗?
解决方案
我有其他具有image方法的模型,所以我只添加了宽度和高度:
public function getImageAttribute()
{
return HTML::image('img/publication/'.$this->published_book_id.'/'.$this->image_file_name, '-', ['class' => 'thumb', 'width' => 150, 'height' => 200]);
}
【问题讨论】:
-
{{ $photo->image }} 包含什么?图片 URL 或图片标签?你能再描述一下吗?
-
您好,@PandhiBhaumik 感谢您的回答。
{{ $photo->image }}的输出为:kinbu.localhost/img/publication/3/Selección_065.png" class="thumb" alt="-"> -
错误做法,为什么要将整个图像标签存储在数据库中?
-
@PandhiBhaumik 有什么建议吗?
-
不,你的做法是对的,我以为你在 DB 中保存了 img 标签,但你使用了自定义模型方法,所以它是正确的。
标签: php laravel laravel-4 blade