我有這個表單編輯文章,更改照片:Laravel上傳的照片上更新
<h1>Edit: {{$article->title}}</h1>
<hr>
{!! Form::model($article, ['method'=>'PATCH','files' => true, 'action'=>['[email protected]', $article->id]]) !!}
@include('articles.form',['submitButtonText'=>'Update Article'])
{!! Form::close() !!}
@include('errors.list')
現在控制器
我有這樣的功能:
public function update($id, Requests\ArticleRequest $request)
{
$photo= 'http://nationaluasi.com/dru/content/hotelIcon.png';
$file = array('photo' => $request->file('photo'));
// setting up rules
$rules = array('photo' => 'required',); //mimes:jpeg,bmp,png and for max size max:10000
// doing the validation, passing post data, rules and the messages
$validator = Validator::make($file, $rules);
if ($validator->fails()) {
// send back to the page with the input data and errors
$photo = 'http://nationaluasi.com/dru/content/hotelIcon.png';
}
else {
// checking file is valid.
if ($request->file('photo')->isValid()) {
$destinationPath = public_path().'/images'; // upload path
$extension = $request->file('photo')->getClientOriginalExtension(); // getting image extension
$photo = str_random(5).'.'.$extension; // renameing image
$request->file('photo')->move($destinationPath, $photo); // uploading file to given path
// sending back with message
}
else {
}
}
$article = Auth::user()->articles()->findOrFail($id);
$article['photo'] = $photo;
$article->update($request->all());
Alert::message('Your auction is updated', 'Wonderful!');
return redirect('auctions');
}
但現在當我試圖提交上傳照片我得到這個結果在列photo
:C:\wamp\tmp\php21F4.tmp
,但也形象上傳到/images
文件夾...
這裏有什麼問題?如何更新的文章......我也想說,就是一切正常,當我添加的文章 - 添加照片等方法store
一切都是相同的,做工精細...
UPDATE:
我嘗試:
$article = Auth::user()->articles()->findOrFail($id);
$article['photo'] = $photo;
dd($photo);
,一切都很好,照片上傳成功地只是我不更新的文章[「照片」] ...所以問題就在這裏:
$物品─>更新($請求 - >所有());
但是如何解決呢?爲什麼文章['照片']沒有更新?
如果您嘗試$ article-> photo = $ photo; $物品─)>保存(; –
不,再次是一樣的... – Andrew