Good night !
I am creating a validation for multiples files for Laravel5. I have this code in PHP who it works if I send an image
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();
}
}
The Request validation
<?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'
];
}
}
When I don't send any images I recieve the following error and I need to control if photo receive an image or not.
Call to a member function getClientOriginalName() on a non-object