在Laravel Orchid中获取上载文件附件的相对URL?
您好,我正在使用Laravel Orchid添加功能将文件上传到服务器。我将(部分)URL发送到存储在硬盘驱动器上的文件中。 我正在使用提供完整URL字符串的$ attactment-> url()检索文件URL,但我想知道如何获取文件的相对URL。
The code I have looks similar to
public function uploadPhoto(Request $request)
{
$file = new File($request->file('fileData'));
$attachment = $file->load();
error_log("Uploaded url". $attachment->url());
return response()->json();
}
This outputs:
http://localhost/storage/2022/06/08/247437ba9e73954388a4a350fc0f292409a679d4.jpg
But I want to get a relative URL:
/storage/2022/06/08/247437ba9e73954388a4a350fc0f292409a679d4.jpg
How can我从Laravel Orchid的附件上获得了上传文件的相对URL?
Hello I am adding the functionality to upload files to the server using the laravel orchid. I am sending the (partial) URL to the file stored on the hard-drive back to the frontend.
I am retrieving the file URL using the $attachment->url() that gives a full URL string but I would like to know how to get a relative URL to the file.
The code I have looks similar to
public function uploadPhoto(Request $request)
{
$file = new File($request->file('fileData'));
$attachment = $file->load();
error_log("Uploaded url". $attachment->url());
return response()->json();
}
This outputs:
http://localhost/storage/2022/06/08/247437ba9e73954388a4a350fc0f292409a679d4.jpg
But I want to get a relative URL:
/storage/2022/06/08/247437ba9e73954388a4a350fc0f292409a679d4.jpg
How can I get a relative URL to the uploaded file from the attachment in Laravel orchid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获取相对于公共文件夹使用的URL
,或者
注意
$ actionment-> url()
还进行额外检查以确认文件是否存在于硬盘驱动器上。To get the url relative to the public folder use
or
Note that
$attachment->url()
additionally does an extra check to confirm that the file exists on the hard drive.