2017-12-06 11 views
1

내 Laravel 프로젝트에서 나는 Excel (.CSV)에서 데이터를 가져옵니다. 소량 데이터 (15 또는 10)를 가져올 때 가져 왔지만 200 개가 넘는 데이터를 업로드하는 경우 (1/1) MethodNotAllowedHttpException. 나는 Maatwebsite/Laravel-Excel 패키지를 사용하여 데이터를 업로드합니다.Laravel Excel 가져 오기 - MethodNotAllowedHttpException

컨트롤러 코드 :

public function uploadleads(Request $request){ 


     $usersid = Auth::user()->id; 

     if($request->hasFile('leads')){ 

      Excel::load($request->file('leads')->getRealPath(), function ($reader) use($usersid) { 

       foreach ($reader->toArray() as $key => $row) { 

        $data['name'] = ucfirst($row['candidatename']); 
        $data['gender'] = ucfirst($row['gender']); 
        $data['mobile'] = $row['mobileno']; 
        $data['email'] = $row['email']; 
        $data['work_experience'] = $row['workexperience']; 
        $data['resume_title'] = $row['resumetitle']; 
        $data['current_location'] = $row['currentlocation']; 
        $data['preferred_location'] = $row['preferredlocation']; 
        $data['current_employer'] = $row['currentemployer']; 
        $data['current_designation'] = $row['currentdesignation']; 
        $data['annual_salary'] = $row['annualsalary']; 
        $data['ug_course'] = $row['ugcourse']; 
        $data['pg_coruse'] = $row['pgcourse']; 
        $data['post_pg_course'] = $row['postpgcourse']; 
        $data['leads_address'] = $row['address']; 
        $data['telephone'] = $row['telephone']; 
        $data['dateofbirth'] = $row['dateofbirth']; 
        $data['sourcefrom'] = $row['sourcefrom']; 
        $data['created_by'] = $usersid; 

       $baseleadscounts=Baseleads::Where('mobile',$row['mobileno'])->OrWhere('email',$row['email'])->count();  

       $templeadscount=Templeads::Where('mobile',$row['mobileno'])->OrWhere('email',$row['email'])->count(); 

       if(($baseleadscounts + $templeadscount) > 0){ 

        DB::table('duplileads')->insert($data); 

       } else { 

        if((preg_match('/(7|8|9)\d{9}/',$data['mobile'])) && ($row['gender'] == 'Male' || $row['gender'] == 'Female' || $row['gender'] == 'male' || $row['gender'] == 'female')){ 

         DB::table('templeads')->insert($data); 

        } else { 

         DB::table('duplileads')->insert($data); 

        } 

       }  

       } 

      }); 
     } 


    alert()->success('Data Imported Successfully.', 'Success!'); 

    return redirect('importreport'); 


    } 

당신이 method='POST'Route::get A와 또는 그 반대의 경우도 마찬가지으로 양식을 제출하려고 할 때 MethodNotAllowedHttpException가 트리거 할 수있는이 문제

+1

경로 확인 – kunal

+0

Route :: post ('uploadleads', 'MasterController @ uploadleads'); - route는 아무런 문제가 없습니다. – Karthik

+0

다음과 같은 방법으로 post 메소드를 호출하고 URL에 액세스합니다 : - localhost : 8000/uploadleads – kunal

답변

0

에게이 오류를 수정하는 방법.

경로가 정확하고 양식이 적절한 방법을 사용하고 있는지 확인하십시오.

+0

그러면 작은 파일을 업로드 할 때 이것이 어떻게 작동할까요? 일치하지 않는 HTTP 메서드 인 경우 어떻게 할 수 있습니까? 그럴 경우 어떤 상황에서도 작동하지 않을 것입니다. – lagbox

+0

한 가지 더, 서버에 파일을 저장하고 그 파일을로드하십시오. 문제가 해결되는지 확인하십시오. –