0
我正在爲Laravel5創建多個文件的驗證。我在PHP它的工作原理誰這個代碼,如果我發送圖像
public function uploadFotos(UploadFotosRequest $request){
$image = $request->file('photo');
$identificador = \Request::input('id');
$pi=PI::find($identificador);
foreach($image as $file){
$fotosPI= new PhotosPI();
$fotosPI->ruta = 'images/punto_interes/'.$pi->id.'/'.$file->getClientOriginalName();
$file->move('images/pi/'.$pi->id.'/', $file->getClientOriginalName());
$fotosPI->creador_id=Auth::user()->id;
$fotosPI->punto_interes_id=$puntoInteres->id;
$fotosPI->save();
}
}
的請求驗證
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class UploadFotosRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'photo' => 'required'
];
}
}
當我不送我收到以下錯誤任何圖像,我需要控制,如果照片是否接收圖像。
Call to a member function getClientOriginalName() on a non-object
什麼是在$圖像?你可以使用XDebug或print_r/var_dump來調試它嗎? – Willian
數組(1){[0] => NULL}我收到一個數組,我需要檢查這個@Willian – jc1992