【问题标题】:Laravel API return link to imageLaravel API 返回图片链接
【发布时间】:2018-11-15 10:34:24
【问题描述】:

对于我的 laravel api,我在 json 中返回一个包含标题和图像链接的对象。

但在 laravel 中我不知道在哪个文件夹中以及如何返回将在移动应用程序上显示的图像的完整链接。

数据保存在 mysql 数据库中

示例:

{
   "title" : "example",
   "image" : "http://www.example.com/images/example.png"
}

感谢您的帮助

------------- 更新 ------------

我添加了一条测试路线:

Route::get('v1/pictures/{filename}',function($filename){
    return asset('/storage/app/public/images/'.$filename);
});

当我打电话时:http://localhost:8000/api/v1/pictures/chat1.jpg 我得到:http://localhost:8000/storage/app/public/images/chat1.jpg

但是当我转到此链接时,出现未找到错误:抱歉,找不到您要查找的页面。

【问题讨论】:

  • 您能详细说明一下吗?任何问题的例子?
  • 图片在文件夹中的链接是什么: /storage/app/public/images/example.png ?以及如何获取此链接

标签: json laravel api


【解决方案1】:
echo asset('/storage/app/public/images/example.png');

这应该回应类似的东西

yourpage.com/storage/bla/bla/example.png

【讨论】:

猜你喜欢
  • 2020-05-22
  • 2019-09-21
  • 1970-01-01
  • 1970-01-01
  • 2019-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-12
相关资源
最近更新 更多