如何在 Laravel 5.3 中显示图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40989290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:34:50  来源:igfitidea点击:

How display image in laravel 5.3

laravellaravel-5.3

提问by shan

I store image in public foldernow i want to display the image i give the path but image not show any one help me whats the wrong in my code

公用文件夹在我的店面形象,现在我要显示的图像我给的路径,但图像没有表现出任何一个可以帮助我什么是我的代码错误

My image complete path is public/admin/product

我的图片完整路径是 public/admin/product

<img src="public/admin/product/<?php echo $productr['image'];  ?>" height="30px" width="30px">

采纳答案by Tayyab Hussain

Laravel view files blade.php supports {{}}tags to display values.

Laravel 视图文件blade.php 支持{{}}标签来显示值。

{{ $valueToBeDisplayed }}

{{ $valueToBeDisplayed }}

In your case, you can do like

在你的情况下,你可以这样做

<img src="/admin/product/{{ $product['image'] }}" height="30px" width="30px" />

Assuming image name is abc.png.

假设图像名称是 abc.png。

Make sure you have that image in folder public/admin/product/abc.png

确保您在文件夹 public/admin/product/abc.png 中有该图像

回答by raphadko

remove public from your path.., also, you might have typos on the variable $productr, (did you mean $product?) try

从您的路径中删除 public ..,此外,您可能在变量 $productr 上有拼写错误,(您的意思是 $product 吗?)试试

<img src="admin/product/<?php echo $product['image'];  ?>" height="30px" width="30px">

or, using blade standard:

或者,使用刀片标准:

 <img src="admin/product/{{ $product['image']; }}" height="30px" width="30px">

回答by Parth Vora

First thing, you should not store those images inside public directory. Instead you should use Storagedirectory. Please have a look to the Laravel documentation:

首先,您不应该将这些图像存储在公共目录中。相反,您应该使用Storage目录。请查看 Laravel 文档:

https://laravel.com/docs/5.3/structure#the-storage-directory

https://laravel.com/docs/5.3/structure#the-storage-directory

So, upload such images inside "storage/app/public"

因此,在“storage/app/public”中上传此类图像

Then fire below artisan command to create symbolic link:

然后在 artisan 命令下触发以创建符号链接:

php artisan storage:link

php工匠存储:链接

And then create a link to that image:

然后创建指向该图像的链接:

<img src="{{ echo asset('storage/file.png') }}" height="30px" width="30px">

回答by Rohit K. Singh

@if ($productr['image'])
<img src="{{ asset('images/profile/'.$productr['image']) }}" alt="{{ $category->user->image }}">
@else
<img src="{{ asset('assets/dist/img/default-150x150.png') }}" >
@endif

回答by sainath kishore

hope this will help

希望这会有所帮助

{{ asset('public/imagepath/image_name') }}