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条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大