You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DataTable图片不显示且点击后出现404错误求助

问题解决步骤
  • 修正图片URL路径
    你的DataTable生成的URL多了public前缀,Laravel存储软链生效后,正确访问路径应为/storage/文件名,而非/public/storage/文件名。修改render函数中的src:

    {
        name: 'file',
        data: 'file',
        "render": function (data, type, full, meta) {
            return "<img src=\"/storage/"+data+"\" height=\"50\"/>";   
        },
        "title": "identity",
        "orderable": true,
        "searchable": true,
    }
    
  • 重新确认storage软链
    先删除现有软链再重建,确保链接指向正确:

    # Linux/Mac系统
    rm public/storage
    php artisan storage:link
    
    # Windows系统(命令提示符)
    rmdir public\storage
    php artisan storage:link
    

    检查项目根目录下的public/storage是否为指向../storage/app/public的软链接(Windows为快捷方式)。

  • 验证文件存储位置
    确认上传的图片确实存放在storage/app/public目录下,文件名与数据库记录完全一致(注意Linux系统区分文件名大小写)。

  • 检查Laravel配置
    打开config/filesystems.php,确保public磁盘配置正确:

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

    同时确认.env文件中APP_URL设置为http://127.0.0.1:8000。

内容的提问来源于stack exchange,提问作者Ricky Ferdinand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 01:35:25