代码之家  ›  专栏  ›  技术社区  ›  Dicky Raambo

Laravel管理图像无法通过URL访问

  •  1
  • Dicky Raambo  · 技术社区  · 6 年前

    我已经创建了一个需要上传图片的应用程序。

    我用 http://laravel-admin.org/

    已经全部设置并遵循文档。所有工作,但我的图像无法通过URL访问

    它说 404 - Not Found

    enter image description here

    通过URL访问时。

    enter image description here

    已在资源管理器上进行了检查。

    enter image description here

    这是我的 config/filesystems.php

    ....
    'disks' => [
    
        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],
    
        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],
    
        'admin' => [
          'driver' => 'local',
          'root' => storage_path('app/public'),
          'visibility' => 'public',
          'url' => env('APP_URL').'/storage',
        ],
    ....
    

    这是我的 config/admin.php

    ....
    'upload' => [
        'disk' => 'admin',
        'directory' => [
            'image' => 'images',
            'file'  => 'files',
        ],
        'host' => 'http://localhost:8000/upload/',
    ],
    ....
    

    任何人都能帮忙解释,被困3小时左右:“”

    1 回复  |  直到 6 年前
        1
  •  0
  •   kenken9999    6 年前

    请参考您的浏览器屏幕,以便图像存储在 public disk / images

    最简单的方法是通过 Storage::disk('public')->url('images/'. $image);

    如果您想创建另一个磁盘,我可以发布更多代码

    也可以使用访问器,在模型中添加此

    public function getShowImageAttribute()
    {
        return \Storage::disk('public')->url('images/'. $this->attributes['image_column_name_here']);
    }
    

    所以你可以像这样在刀刃上接近它

    {{ $user->show_image }}
    
    推荐文章