【发布时间】:2017-04-14 22:09:25
【问题描述】:
我的应用程序中的每个用户都有一张封面照片,就像 Facebook 一样。我已经尝试了好几天才能更新它,但现在我被卡住了。当我点击更新时,我的用户之前的照片会被删除,新照片不会出现,我的默认照片会出现。
这是我的控制器
public function updateCover(Request $request, $id)
{
$user = User::findorFail($id)->with('cover_id');
$input = $request->all();
$input = Input::file('cover_id');
$filename = time() . '.' . $input->getClientOriginalExtension();
$path = public_path('images' . $filename);
Photo::make($input->getRealPath())->save($path);
$user->cover = 'images'.$filename;
$user->save();
}
我对表单的看法
{!! Form::model($user, ['method'=>'PUT', 'action'=>
['UserController@updateCover', $user->id], 'files'=>true]) !!}
{!! Form::file('cover_id', ['class'=>'form-control']) !!}
我不是 laravel 方面的专家,所以就我所知,我可能完全错了,我只是想在更新时更改封面照片。
【问题讨论】: