我正在尝试从存储文件夹访问图像以在刀片视图中显示。这些图像在存储/应用/照片中。
我已经运行了一个php artisan storage:link命令,但是仍然没有显示图像的运气。
这是我的家庭管理员
public function detailPro($id) {
$products=DB::table('products_photos')
->join('products','products_photos.product_id','products.id')
->get();
//dd($products);
return view('front.product_detail', compact('products'));
}
这是我的detail.blade.php
@foreach($products as $product)
<div class="col-md-6 col-xs-12">
<div class="thumbnail">
</div>
<img src="{{ url('storage/app/photos/'.$product->filename) }}" style="width:200px;" alt="">
</div>
@endforeach
这是我将图像保存到db的逻辑
public function store(Request $request)
{
$product = Product::create($request->all());
foreach ($request->photos as $photo) {
$filename = $photo->store('photos');
ProductsPhoto::create([
'product_id' => $product->id,
'filename' => $filename
]);
}
return 'Upload successful!';
}
该图片未显示,并且显示的网址是此“ http://127.0.0.1:8000/storage/app/photos/photos/xPNOQQTaTjPaKUClAHOxx7NEjsNLHguhVuAryZEg.jpeg”。
答案 0 :(得分:1)
您应检查this,如果已经运行Storage::url('url')
,则可以使用php artisan storage:link
@foreach($products as $product)
<div class="col-md-6 col-xs-12">
<div class="thumbnail">
</div>
<img src="{{ Storage::url($product->filename) }}" style="width:200px;" alt="">
</div>
@endforeach
将您的store
方法更改为
public function store(Request $request)
{
$product = Product::create($request->all());
foreach ($request->photos as $photo) {
$filename = $photo->store('public/photos');
ProductsPhoto::create([
'product_id' => $product->id,
'filename' => $filename
]);
}
return 'Upload successful!';
}
答案 1 :(得分:0)
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
<img src="{{ url('/storage/'.$product->filename)}}" style="width:200px;" alt="">
然后你会没事的;)
答案 2 :(得分:0)
在刀片上,尝试以下操作:
@foreach($products as $product)
<div class="col-md-6 col-xs-12">
<div class="thumbnail">
</div>
<img src="{{ url('photos/'.$product->filename) }}" style="width:200px;" alt="">
</div>
@endforeach