Laravel API返回图像链接

问题描述 投票:-1回答:1

对于我的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

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

json laravel api
1个回答
0
投票
echo asset('/storage/app/public/images/example.png');

这应该回应像

yourpage.com/storage/bla/bla/example.png
© www.soinside.com 2019 - 2024. All rights reserved.