图像不会在视图中显示laravel 5.6

时间:2018-07-21 10:53:31

标签: php laravel image

我正在将图像存储在存储文件夹中,并将URL存储在数据库中,但是当我想在视图中显示它们时,这里找不到我的代码:

控制器

// set a default visibility to View for position
// apply visibility to view 
// When visibility change for any event then change visibility and save it for position
// when getView is called for a position then use previously saved visibility for position

视图:

  $filename = $request->file('agreement')->store('public/images');
    $client = Client::create([
        'title' => $request->title,
        'description' => $request->description,
        'fax'=>$request->fax,
        'adrress1'=>$request->adrress1,
        'telephone1'=>$request->telephone1,
        'client_type'=>$request->client_type,
        'sellpercent'=>$request->sellpercent,
        'agreement'=>$filename,
    ]);
    return redirect('admin/client/'.$client->id);

我尝试手动将文件从存储设备移动到主公用文件夹,但是即使我将URL放在浏览器中也无法正常工作,但在运行命令后出现未找到错误

 <img src="{{url($client->agreement)}}" alt="some thing">

但还是没有任何反应,这是我保存在数据库中的URL

php artisan storage:link

2 个答案:

答案 0 :(得分:1)

使用资产:

 <img src="{{asset($client->agreement)}}" alt="some thing">

并将此路径存储在数据库中:

images/KMrCn80Cc9jlNqwLhcSjGM7JJ09lob6cnJGDuTel.jpeg

答案 1 :(得分:1)

您已经使用storage/app/public创建了public/storagephp artisan storage:link文件夹的符号链接。因此,现在您只需要使用public磁盘上传文件

$filename = $request->file('agreement')->store('subfolder', 'public');

文件的物理路径在storage/app/public/subfolder,但是由于您有storage/app/publicpublic/storage的符号链接。现在,您可以使用asset这样在视图中公开访问

{{asset('storage/subfolder/' . $client->agreement)}}