[英]Images not displaying from public folder in Laravel 9
根据我的研究,有人告诉我运行php artisan storage:link
不起作用,我的特色图像也没有显示,其他图像的 rest 也没有。 在我的配置 /filesystems.php 中,我还将默认路径从“本地”切换到“公共”,但没有成功。 任何帮助表示赞赏。
帖子 Controller
if ($request->hasFile('image')) {
$image = $request->file('image');
$image_name = $image->getClientOriginalName(); // Add time() . '.' . to show image upload time
$image->move('public/thumbnails', $image_name);
$request->image = $image_name;
}
if($request->has('featured')) {
Posts::where('featured', '=',1)
->update(['featured' => false]);
}
Posts::create([
'title' => $request->post('title'),
'image' => $image_name,
'sub_title' => $request->post('sub_title'),
'tags' => $request->post('tags'),
'content' => $request->post('content'),
'featured' => ($request->has('featured')) ? true : false,
]);
索引视图
//Featured Post
@foreach ($featuredPosts as $featured)
<img src="{{ $featured->image ? Storage::disk('public')->url($featured->image) : asset('assets/frontend/img/example.png') }}" alt="">
@endforeach
//Normal Post
@foreach ($paginate as $post)
<img src="{{ $post->image ? Storage::disk('public')->url($post->image) : asset('assets/frontend/img/example.png') }}" alt="" >
@endforeach
if (! File::exists("uploads/properties")) {
File::makeDirectory("uploads/properties");
}
if (! File::exists(public_path()."uploads/properties")) {
File::makeDirectory(public_path()."uploads/properties");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.