我是Laravel的新手,所以我真的需要一些幫助。我想問什麼時候 我評論部分'photo'=>要求爲什麼如果我更新而不輸入照片它顯示一些錯誤,如調用成員函數getClientOriginalName()null。所以真正的問題是我想更新而不輸入照片,它應該仍然是更新。PHP - 調用成員函數getClientOriginalName()null並刪除警報laravel
這是我在控制器代碼上傳照片
public function update($id, UpdateBannerRequest $request)
{
$input = $request->all();
//get original file name
$filename = Input::file('photo')->getClientOriginalName();
$input['photo'] = $filename;
Input::file('photo')->move($this->path, $filename);
$banner = $this->BannerRepository->findWithoutFail($id);
if (empty($banner)) {
Flash::error('Banner not found');
return redirect(route('banner.index'));
}
$banner = $this->BannerRepository->update($input, $id);
Flash::success('Banner updated successfully.');
return redirect(route('banner.index'));
}
這是我的模型
<?php
命名空間應用\模型的代碼;
使用Eloquent as Model; 使用Illuminate \ Database \ Eloquent \ SoftDeletes;
class Banner extends Model { use SoftDeletes;
public $table = 'banners';
protected $dates = ['deleted_at'];
public $fillable = [
'title',
'description',
'photo',
'status'
];
protected $casts = [
'title' => 'string',
'description' => 'string',
'photo' => 'string',
'status' => 'integer'
];
public static $rules = [
'title' => 'required',
'description' => 'required',
//'photo' => 'required',
'status' => 'required'
];
}
'Input :: file('photo')'不是一個對象 – Scuzzy
所以當沒有進入照片的更新會出現'沒有找到圖片'像這樣的照片http://imgur.com/a/qzDVc –
@Scuzzy hello感謝您的回覆,那麼我該如何處理這個問題? –