Media Finder display Image on Front End

青春壹個敷衍的年華 提交于 2019-12-10 12:00:00

问题


I created a Model and Database and can upload an image using the Media Finder.

I set Media Finder field as photo in fields.yamal.

But after uploading, no image path is saved to the database in the photo column.


Database Tables

  • id (integer)
  • title (string)
  • photo (string)

Twig

{% for product in builderListCatalog.records %}
    {{ product.title }}
    <img src="{{ product.photo }}" />
{% endfor %}

This successfully displays the Title but not the Photo path because it is empty in the database.


回答1:


You need to remove all the relation added to that field from model.

You are using public $attachOn remove it that is the issue now its treated like file attachment relation not a finder image so it will not store path of image in that photo (string) field in table

If you use media finder you just need to add normal string (photo) field in table no need to add any relation in model and it will just store selected file path in that field for ex. /someimage.png

Now to show it in front-end you can use

<img src="{{ model.photo|media }}" />

In component partial you can use

<img src="<?php echo 'https://october-plaza.com/storage/app/media/' . $model->photo ?>" />

if any doubt please comment.



来源:https://stackoverflow.com/questions/50648796/media-finder-display-image-on-front-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!