doufendi9063 2017-01-17 17:54
浏览 109
已采纳

Laravel - 无法加载资源

I'm using the Image Intervention package in Laravel and I can't display my profile image. The problem is that the browser fails to load the resource

localhost:8000/uploads etc. 

All files are saved in public folder :

public/uploads

My view:

<div class="row">
    <div class="col-md-2 ">
        <img src="uploads/{{ $user->avatar }}">
    </div>
</div>

Controller:

class UserController extends Controller
{
    public function profile()
    {
        return view ('user.profile', array('user'=>Auth::user()));
    }

    public function update(Request $request)
    {
        if($request->hasFile('avatar'))
        {
            $avatar = $request->file('avatar');
            $filename = time() . '.' . $avatar->getClientOriginalExtension();
            Image::make($avatar)->resize(300, 300)->save(public_path('/uploads/avatar' . $filename));
            $user = Auth::user();
            $user->avatar = $filename;
            $user->save();
        }
        return view('user.profile',array('user'=>Auth::user()));
    }
}

I'm using windows and i see these files saved in my folder public/uploads but i cant display it

Regards

  • 写回答

2条回答 默认 最新

  • duanpu8830 2017-01-17 18:56
    关注

    In your controller class change this line:

    $user->avatar = $filename;
    

    to this:

    $user->avatar = 'avatar' . $filename;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程