laravel - 无法使用 Cloudinary 和 Laravel 显示图像
问题描述
我正在尝试使用 cloudinary 来保存我的图像,下面的代码可以将图像保存到 cloudinary,但无法在我的视图中显示图像。
public function store(Request $request)
{
$image = $request->file('image');
$name = $request->file('image')->getClientOriginalName();
$destinationPath = 'images/';
$image = $request->file('image')->getRealPath();;
Cloudder::upload($image, null);
list($width, $height) = getimagesize($image);
$image_url= Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height"=>$height]);
.
.
.
return redirect ( route ('admin.book.index'));
}
在我的view page
,我有这个
@foreach($books as $book)
<div class="col-1-5">
<div class="home-catalog-image">
<a href="{{ $book->image_url }}" target="_blank">
<img src="{{ $book->image }}" alt="trending image" />
</a>
</div>
<p class="author">{{ $book->author->name }}</p>
<h1 class="book-title">{{str_limit($book -> name, 20) }}</h1>
</div>
@endforeach
我已经将它包含在我的控制器中
public function index()
{
$books = Book::orderBy('created_at', 'desc')->take(10)->get();
return view('bookpage')->with('books', $books);
}
更新
在我的研究过程中,我更新了我的代码,但它返回错误调用字符串上的成员函数 move()
$image = $request->file('image');
$name = $request->file('image')->getClientOriginalName();
$destinationPath = 'images/';
$image = $request->file('image')->getRealPath();;
Cloudder::upload($image, null);
list($width, $height) = getimagesize($image);
$image_url= Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height"=>$height]);
//save to uploads directory
$image->move(public_path("uploads"), $name);
//Save images
$this->saveImages($request, $image_url);
解决方案
问题出在我看来
@foreach($books as $book)
<div class="col-1-5">
<div class="home-catalog-image">
<a href="{{ $book->image_url }}" target="_blank">
<img src="{{ $book->image_url }}" alt="trending image" />
</a>
</div>
<p class="author">{{ $book->author->name }}</p>
<h1 class="book-title">{{str_limit($book -> name, 20) }}</h1>
</div>
@endforeach
推荐阅读
- amazon-web-services - AWS - 回溯 Aurora 数据库
- python - queue.py 中 Queue 类的功能是什么?
- google-colaboratory - Google Colab:如何挂载特定文件夹而不是挂载根文件夹?
- linux - 无法在 Ubuntu 命令行中启动 WebdriverIO
- java - sql插入中单引号的正则表达式
- simulink - 如何在simulink中更改任务优先级
- ios - 如果不在客户端以确保安全,我应该在哪里存储我的 FCM 服务器密钥?IOS?
- asp.net-mvc - 下拉列表未在编辑页面上显示值
- javascript - 在重定向的页面中出现 Redux 状态错误
- sql - 如何在从另一个表中提取数据时创建具有约束的表