Laravel 8,从数据库中重新查看的图像url不返回图像
我为这个问题挣扎了好几个小时。我的问题是,我的数据库中保存了一个图像url,当我检索它时,我试图在index.blade.php中显示它。奇怪的是,我在一个旧项目中使用了相同的代码,它工作了,但我打开了旧项目,它也不再工作了。我已经做了Laravel 8,从数据库中重新查看的图像url不返回图像,laravel,Laravel,我为这个问题挣扎了好几个小时。我的问题是,我的数据库中保存了一个图像url,当我检索它时,我试图在index.blade.php中显示它。奇怪的是,我在一个旧项目中使用了相同的代码,它工作了,但我打开了旧项目,它也不再工作了。我已经做了php artisan storage:link,从我看到的链接是正确的,但图像显示为断开,我查找了各种解决方案,但所有这些都导致了死胡同,因为url只是不想显示图像。图像url保存在此表单中 My index.blade.php tbody <tbod
php artisan storage:link
,从我看到的链接是正确的,但图像显示为断开,我查找了各种解决方案,但所有这些都导致了死胡同,因为url只是不想显示图像。图像url保存在此表单中
My index.blade.php tbody
<tbody>
@foreach($companies as $company)
<tr>
<td scope="row">{{$company->id}}</td>
<td>{{$company->name}}</td>
<td>{{$company->email}}</td>
<td><img class="class='img-fluid rounded mb-3 mb-lg-0 ml-md-0" src="{{$company->logo}}"></td>
<td>{{$company->url}}</td>
<td>
<a href="{{route('company.edit', $company->id)}}" class="float-left">
<button type="button"
class="btn btn-primary mr-2">{{__('Edit')}}</button>
</a>
<form action="{{route('company.delete',$company->id)}}" method="POST"
class="float-left">
{{method_field('DELETE')}}
@csrf
<button type="submit"
class="btn btn-danger btn-sn">{{__('Delete')}}</button>
</form>
</td>
</tr>
@endforeach
</tbody>
如何存储我的图像url
public function store(Request $request): RedirectResponse
{
$request->validate([
'name' => 'required',
'email' => '',
'logo' => 'dimensions:min_width:100,min_height:100',
'url' => ''
]);
$parameters = $request->all();
if ($request->logo !== null) {
$image = $request->logo->store('public');
$parameters['logo'] = URL::to('/') . '/storage/' . $image;
}
$this->company->create($parameters);
return redirect()->route('company.index');
}
我不确定这是否足够,但我想这些是主要部分。默认情况下
php artisan storage:link
使用存储/app/public
创建一个符号链接,因此将图像从存储/public
移动到存储/app/public
。然后您可以通过http://127.0.0.1:8000/storage/vsX9ihmRknGWLXtNRmxgCXV3ckqhlFoBlyuMoejB.png
默认情况下php artisan storage:link
使用storage/app/public
创建一个符号链接,以便将图像从storage/public
移动到storage/app/public
。然后您可以通过http://127.0.0.1:8000/storage/vsX9ihmRknGWLXtNRmxgCXV3ckqhlFoBlyuMoejB.png
谢谢你,你是救命恩人
public function store(Request $request): RedirectResponse
{
$request->validate([
'name' => 'required',
'email' => '',
'logo' => 'dimensions:min_width:100,min_height:100',
'url' => ''
]);
$parameters = $request->all();
if ($request->logo !== null) {
$image = $request->logo->store('public');
$parameters['logo'] = URL::to('/') . '/storage/' . $image;
}
$this->company->create($parameters);
return redirect()->route('company.index');
}