[英]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.