微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我在Laravel Excel 3.1队列导入时遇到错误

如何解决我在Laravel Excel 3.1队列导入时遇到错误

服务器ENV

  • PHP 7.4
  • maatwebsite / excel 3.1

我尝试使用与https://docs.laravel-excel.com/3.1/imports/queued.html相关的队列导入,但是我得到了[2020-10-25 01:18:56] [16]失败:Maatwebsite \ Excel \ Jobs \ ReadChunk一直在我的工作队列上。

public function import(Request $request){
    if (Auth::guard('web')->user()->hasRole('Collector')){
        return abort('404');
    }

    try {
        Excel::queueImport(new CustomerImport(),$request->file('import_file'));
        return back()->with('success','Upload Success');
    } catch (\Exception $exception) {
        return back()->with('danger','An Error when uploading file. Please try again');
    }
}

CustomerImport File

<?PHP

namespace App\Imports;

use App\Http\Controllers\Controller;
use App\Models\CustomerAddress;
use App\Models\CustomerEmergencyContact;
use App\Models\CustomerMainData;
use Illuminate\Contracts\Queue\ShouldQueue;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;
use Maatwebsite\Excel\Concerns\WithChunkReading;

class CustomerImport extends Controller implements ToModel,WithStartRow,WithChunkReading,ShouldQueue
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        $data = CustomerMainData::where('contract_no',$row[6])->where('customer_code',$row[4])->first();
        if (empty($data)) {
            $data = new CustomerMainData([
                'assign_date' => $this->encodeThaiCarbon($row[0]),'expiry_date' => $this->encodeThaiCarbon($row[1]),'id_no' =>$row[2],'birth_date' => $this->encodeThaiCarbon($row[3]),'customer_code' => $row[4],'name' => $row[5],'contract_no' => $row[6],'contract_date' => $this->encodeThaiCarbon($row[7]),'wo_date' => $this->encodeThaiCarbon($row[8]),'contact_term' => $row[9],'installment_amount' => $row[10]/100,'over_due_status' => $row[11],'loan_amount' => $row[12]/100,'wo_balance' => $row[13]/100,'over_due_amount' => $row[14]/100,'penalty_amount' => $row[15]/100,'closing_amount' => $row[16]/100,'receive_status_od2' => $row[17],'receive_amount_before' => $row[18]/100,'receive_amount_after' => $row[19]/100,'last_pay_amount' => $row[20]/100,'last_pay_date' => $this->encodeThaiCarbon($row[21]),'no_assign' => $row[22],'product_desc' => $row[23],'provider_note' => $row[54],'loan_type' => $row[55],'oa_fee' => $row[59]/100,'max_oa_fee_amount' => $row[60]/100,'max_oa_fee_balance' => $row[61]/100,'oa_flag' => $row[62],'send_flag' => $row[63],]);
        } else {
            $data->fill([
                'assign_date' => $this->encodeThaiCarbon($row[0]),]);
        }

        $data->save();
        $address = CustomerAddress::where('customer_main_data_id',$data->id)->first();

        if (empty($address)) {
            $address = new CustomerAddress([
                'customer_main_data_id' => $data->id,'home_address_1' => $row[24],'home_address_2' => $row[25],'home_address_3' => $row[26],'home_address_4' => $row[27],'home_telephone' => $row[28],'home_mobile' => $row[50],'office_address_1' => $row[29],'office_address_2' => $row[30],'office_address_3' => $row[31],'office_address_4' => $row[32],'office_telephone' => $row[33],'office_mobile' => $row[51],'identification_address_1' => $row[34],'identification_address_2' => $row[35],'identification_address_3' => $row[36],'identification_address_4' => $row[37],'identification_telephone' => $row[52],'identification_mobile' => $row[53],]);
        } else {
            $address->fill([
                'home_address_1' => $row[24],]);
        }

        $address->save();
        $emergency_contact = CustomerEmergencyContact::where('customer_main_data_id',$data->id)->first();

        if (empty($emergency_contact)) {
            $emergency_contact = new CustomerEmergencyContact([
                'customer_main_data_id' => $data->id,'contact_name_1' => $row[38],'contact_phone_1' => $row[39],'contact_phone_ext_1' => $row[40],'contact_name_2' => $row[41],'contact_phone_2' => $row[42],'contact_phone_ext_2' => $row[43],'contact_name_3' => $row[44],'contact_phone_3' => $row[45],'contact_phone_ext_3' => $row[46],'contact_name_4' => $row[47],'contact_phone_4' => $row[48],'contact_phone_ext_4' => $row[49],]);
        } else {
            $emergency_contact->fill([
                'contact_name_1' => $row[38],]);
        }
        $emergency_contact->save();
        return $data;
    }

    public function startRow(): int
    {
        return 2;
    }

    public function chunkSize(): int
    {
        return 100;
    }
}

错误日志

local.ERROR: Too few arguments to function Illuminate\Routing\Controller::middleware(),0 passed in /Users/topkst/PHPstormProjects/easy-buy/vendor/maatwebsite/excel/src/Jobs/ReadChunk.PHP on line 101 and at least 1 expected {"exception":"[object] (ArgumentCountError(code: 0): Too few arguments to function Illuminate\\Routing\\Controller::middleware(),0 passed in /Users/topkst/PHPstormProjects/easy-buy/vendor/maatwebsite/excel/src/Jobs/ReadChunk.PHP on line 101 and at least 1 expected at /Users/topkst/PHPstormProjects/easy-buy/vendor/laravel/framework/src/Illuminate/Routing/Controller.PHP:23)

如何解决错误。我尝试修复2天,但是我不能

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。