【问题标题】:how to show images back from database that are saved in public images directory laravel如何从数据库中显示保存在公共图像目录laravel中的图像
【发布时间】:2017-10-09 03:55:36
【问题描述】:

我在上面停留了一段时间,现在有一些明显的东西丢失了,但在i am trying to retrieve the images by the loop 我试图通过循环检索图像的那一刻找不到它

这是保存它的代码,它工作正常。 [保存图片的代码]

这是我尝试将其取出时得到的结果404 error upon retriveing image

【问题讨论】:

  • 你能分享Tour类的代码吗?以及如何将图像保存在数据库中?
  • 检查你的 images 文件夹是否在 travel/public/admin 文件夹下,如果不是,改变你渲染资源的方式
  • 这里是(Tour 类代码)类 Tour extends Authenticatable { use Notifiable; /** * 可批量分配的属性。 * * @var array */ protected $fillable = ['name','location','contact','photo_id','service','description', ]; public function photo(){ return $this->belongsTo('App\Photo'); }
  • @CodeIsLife 我的图片在公共图片文件夹中

标签: php image laravel laravel-5 laravel-5.4


【解决方案1】:

你的图片路径是 public/images/404.png 我猜 使用asset 或url

<img src="{{$tour->photo->file ? asset('images/'.$tour->photo->file): asset('images/404.png')}}">

<img src="{{$tour->photo->file ? url('images/'.$tour->photo->file): url('images/404.png')}}">

【讨论】:

  • 感谢大家对我的帖子做出回应,非常感谢您的所有支持 :) 祝福@Hamel Raj,感谢您的回答。有效。 :)
猜你喜欢
  • 1970-01-01
  • 2020-08-17
  • 1970-01-01
  • 1970-01-01
  • 2016-07-27
  • 2015-04-18
  • 1970-01-01
  • 2020-06-01
  • 2014-06-14
相关资源
最近更新 更多