如何从Amazon S3存储中的Laravel中的Blade显示多个图像?

发布于 2025-02-13 17:43:49 字数 132 浏览 1 评论 0原文

我有book模型,并且有一个名为cover的字段,其中保存图像链接。

我想从书籍的Collection中从S3存储中获取图像的链接。 我该怎么做?

I have Book model and there is a field called cover, where I save image link.

I want to get images' links from S3 storage in Collection of Book.
How can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亚希 2025-02-20 17:43:50

由于您没有提供前端的详细信息,因此我认为您正在使用刀片。

要获取集合中的所有书籍的图像并在前端显示它们,您应该这样做:(

yourcontroller.php)

public function collection(User $user){
   $collection = Collection::where('user_id', $user->id)->first();
   $books = $collection->books;
   return view('collection', compact('collection', 'books'));
}

在您的视图中,您想foreach每本书。

@foreach($books as $book)
    <img src="{{Storage::disk('s3')->temporaryUrl('directoryWhereYouStoredYourFiles/' . $book->featured_image, now()->addMinutes(30))}}" alt="cover">
@endforeach

As you did not provide details on your front-end, I assume you're using blade for it.

To get the images of all the books inside the collection and show them in the front-end, you should do it something like this:

(YourController.php)

public function collection(User $user){
   $collection = Collection::where('user_id', $user->id)->first();
   $books = $collection->books;
   return view('collection', compact('collection', 'books'));
}

In your view, you'd like to foreach each book.

@foreach($books as $book)
    <img src="{{Storage::disk('s3')->temporaryUrl('directoryWhereYouStoredYourFiles/' . $book->featured_image, now()->addMinutes(30))}}" alt="cover">
@endforeach
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文