简体   繁体   English

如何在laravel API 中获取图像的完整路径?

[英]How to get the full path of an image in laravel API?

I want to get the path of an image using mutators or helper function for example this is My request :我想使用 mutators 或 helper 函数获取图像的路径,例如这是我的请求:

 "placeType": {
        "id": 1,
        "name": "Kenya Wyman",
        "image_name": "1574668070.png",
        "status": 1,
}
}

I want it to appear like this :我希望它看起来像这样:

 "placeType": {
        "id": 1,
        "name": "Kenya Wyman",
        "image_name": "www.mydomain.com/photos/1574668070.png",
        "status": 1,
}
}

Try This尝试这个

$user->image_name = url('public/Your path ' . $user->image_name);

OR或者

In your Model Add this在你的模型中添加这个

public function getImageNameAttribute($value)
{

        return public_path($value);
}

尝试使用此代码:

$data->image_name = URL::to('/') . '/public/imageFolder/' . $placeType->image_name;

Try to use this code :尝试使用此代码:

asset('photos/1574668070.png');资产('照片/1574668070.png');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM