存储/应用程序/公开 - >这是我的图像存储路径。如何检索存储在laravel5.4存储文件夹中的图像?
控制器代码:
public function addDeviceCategory(Request $cform)
{
if (Input::hasFile('imagefile'))
{
$name = $this->getImageId().".".$cform->file('imagefile')-
>getClientOriginalExtension();
$image = $cform->file('imagefile');
$resize = Image::make($image)->resize(700, 300)->encode($cform-
>file('imagefile')->getClientOriginalExtension());
$hash = md5($resize->__toString());
$path = "public/" . $name;
Storage::put($path, $resize->__toString());
}
$validation1=deviceCategory::select('deviceCategoryName')-
>where("deviceCategoryName",$cform->deviceCategory)->first();
if(is_null($validation1))
{
$temp=new deviceCategory;
$temp->deviceCategoryId=$this->getDeviceCategoryId();
$temp->deviceCategoryName=$cform->input('deviceCategory');
$temp->subCategoryId=$cform->input('subCategory');
$temp->image=$name;
$temp->save();
return redirect('formAddDeviceCategory');
}
}
public function getImageId(){
return md5(uniqid().microtime());
}
这是我存储的图像转换成laravel的存储路径的方式.The(即存储/应用程序/公共)。存储在这里成功完成。
查看代码:
@php
$l=1
@endphp
@foreach($cdetails as $cdetail)
<tr>
<td>{{$l++}}</td>
<td>{{$cdetail->deviceCategoryId}}</td>
<td>{{$cdetail->categoryName}}</td>
<td>{{$cdetail->subCategoryName}}</td>
<td>{{$cdetail->deviceCategoryName}}</td>
**<td><img src="{{ asset('storage/app/public/$cdetail->
image') }}" width="50" height="50"></img></td>**
@endforeach
在这里,我试图显示存储image.But没有显示在那里。
尝试过'{{asset($ cdetail-> image)}}'? – linktoahref
是的。但它只显示存储在公共文件夹 –
中的图像对不起,我的坏!我有点无知 – linktoahref