Gute Nacht!Wie man multiple Fotos überprüft, wenn null ist
Ich erstelle eine Validierung für mehrere Dateien für Laravel5. Ich habe diesen Code in PHP, die es funktioniert, wenn ich ein Bild senden
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();
}
}
Der Antrag Validierung
<?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'
];
}
}
Wenn ich senden keine Bilder ich folgende Fehlermeldung empfangen, und ich brauche zu kontrollieren, wenn Foto erhält ein Bild oder nicht.
Call to a member function getClientOriginalName() on a non-object
Was ist drin $ image? Können Sie es mit XDebug oder print_r/var_dump debuggen? – Willian
Array (1) {[0] => NULL} Ich erhalte ein Array, ich muss dies überprüfen @Willian – jc1992