查看图像Laravel时找不到404页面

时间:2017-05-05 10:18:09

标签: laravel-5

我有一个图像存储在数据库中 convention / convention_title.jpg

该文件位于“storage / app / conventions / convention_title.jpg”

当我做类似此传单的事情}}“>”时,它不显示......

传单}}“> 图片仍然无法显示...

更糟糕的是,如果我尝试通过这样的链接直接访问图像......

http://localhost:8000/storage/app/convention/convention_title.jpg 我收到了一个未找到错误的视图 - >找不到404页..

这可能是什么原因?

3 个答案:

答案 0 :(得分:1)

  1. php artisan storage:link
  2. 编写时解决了问题
src=" {{ asset('/storage/'.$post->image) }}"

答案 1 :(得分:0)

网页内容必须存储在laravel root /public文件夹中,您可以通过asset helper轻松访问它。

例如:

/public/img/conventions/convention_title.jpg

然后你可以访问它的视图,如:

{{ asset("/img/conventions/convention_title.jpg")}}

如果您想测试是否可以访问图像,可以尝试:

http://localhost:8000/convention/convention_title.jpg

答案 2 :(得分:0)

您可以在 config / filesystems.php

中创建新磁盘
'disks' => [
    'local' => [
        'driver' => 'local',
        'root'   => storage_path(),
    ],
    'uploads' => [
        'driver' => 'local',
        'root'   => public_path() . '/uploads',
    ],
]

然后使用它:

Storage::disk('uploads')->put('filename', $file_content);

或者你可以做这个简单的方法

$request->file('photo')->move(public_path("/uploads"), $newfilename);

然后,使用上述任何方法,您仍然可以使用asset()辅助函数访问您的图像......

相关问题