dpzlz08480 2016-05-16 21:51
浏览 17
已采纳

如果为null,如何检查倍数fotos

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
  • 写回答

1条回答 默认 最新

  • douke8473 2016-05-16 22:09
    关注

    Try to remove false values (after casting) with array_filter:

    $image = array_filter($request->file('photo'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度