我能够将图像存储在所需位置,但我无法查看。 重新加载页面时,将显示相同的默认图像。 默认图像永远不会更改为我想要的图像。
我的控制器文件(UserController.php):
public function update_avatar(Request $request)
{
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$filename = time(). '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->save(public_path('/src/uploads/avatars/' . $filename));
}
return redirect()->route('dashboard');
}
}
我的路线档案:
Route::post('/dashboard',[
'uses'=>'UserController@update_avatar',
]);
我的观点文件:
<form action="/dashboard" method="post" enctype="multipart/form-data">
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<input type="file" name="avatar" class="btn btn-sm btn-primary col-md-5" >
<input type="submit" class="pull-right btn btn-sm btn-primary " value="submit">
<input type="hidden" value="{{Session::token() }}" name="_token">
<a href="#">Remove</a>
</div>
<div id="main">
<span style="font-size:30px;cursor:pointer" onclick="openNav()"><img src="download.jpg" class="img-circle img-responsive" alt="Placeholder image"></span>
</div>
</form>
答案 0 :(得分:0)
根据您的需要更改具有头像属性的用户
public function update_avatar(Request $request)
{
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$path = '/src/uploads/avatars/';
$filename = time(). '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->save(public_path($path . $filename));
$request->user()->avatar = $filename;
$request->user()->save();
}
return redirect()->route('dashboard');
}