第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Laravel 文件上傳時(shí)無法識(shí)別文件錯(cuò)誤“Call to a member function ”

Laravel 文件上傳時(shí)無法識(shí)別文件錯(cuò)誤“Call to a member function ”

PHP
夢(mèng)里花落0921 2023-10-21 15:47:20
我正在使用 Laravel、Ajax 和 Datatables 來管理我的信息,一切正常,但我需要將文件上傳到其中。但我收到 Call to a member function store() on null。這是控制器功能的代碼(post 和 fetch):    function postdata(Request $request)    {        $validation = Validator::make($request->all(), [            'referencia'  => 'required',            'tipo_equipo'  => 'required',            'tipo_servicio'  => 'required',            'id_reporte'  => 'required',        ]);        $error_array = array();        $success_output = '';        if ($validation->fails())        {            foreach($validation->messages()->getMessages() as $field_name => $messages)            {                $error_array[] = $messages;            }        }        else        {            if($request->get('button_action') == 'update')            {                $servicio = Servicio::find($request->get('servicio_id'));                $servicio->referencia = $request->get('referencia');                $servicio->tipo_equipo = $request->get('tipo_equipo');                $servicio->tipo_servicio = $request->get('tipo_servicio');                $servicio->id_reporte = $request->get('id_reporte');                $servicio->imagen_inicio = $request->file('imagen_inicio')->store('public/img/servicio');                $servicio->imagen_fin = $request->get('imagen_fin');                $servicio->pdf_reporte = $request->get('pdf_reporte');                $servicio->save();                $success_output = '<div class="alertaTables alert alert-success">Servicio Actualizado</div>';            }        }        $output = array(            'error'     =>  $error_array,            'success'   =>  $success_output        );        echo json_encode($output);    }
查看完整描述

1 回答

?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊

它不允許您存儲(chǔ)文件,因?yàn)槲募o法發(fā)送到服務(wù)器,因?yàn)槟褂?AJAX 發(fā)出請(qǐng)求,要通過 AJAX 發(fā)送文件,請(qǐng)嘗試以下操作:


$('#servicio_form').on('submit', function(event){

   event.preventDefault();


   // init formData and get files

   let formData = new FormData($('#servicio_form')[0]);

   let imagenInicio = $('#imagen_inicio')[0].files[0];

   let imagenFin= $('#imagen_fin')[0].files[0];

   let pdfReporte= $('#pdf_reporte')[0].files[0];


   // append files to formData

   formData.append('imagen_inicio', imagenInicio);

   formData.append('imagen_fin', imagenFin);

   formData.append('pdf_reporte', pdfReporte);


   // in AJAX disable contentType, processData and cache

   $.ajax({

      url:"{{ route('mis-servicios.postdata') }}",

      method:"POST",

      dataType:"json",

      data: formData,       // change this and the following options

      contentType: false, 

      processData: false,

      cache: false,

      success: function(data) {

         // your code...

      }

   });

});


查看完整回答
反對(duì) 回復(fù) 2023-10-21
  • 1 回答
  • 0 關(guān)注
  • 262 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)