2016-05-16 68 views
0

晚安!如何檢查倍數fotos是否爲空

我正在爲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 
+0

什麼是在$圖像?你可以使用XDebug或print_r/var_dump來調試它嗎? – Willian

+0

數組(1){[0] => NULL}我收到一個數組,我需要檢查這個@Willian – jc1992

回答

1

嘗試與array_filter去除假值(後鑄造):

$image = array_filter($request->file('photo')); 
+0

是的,它的工作原理;) – jc1992