/
home
/
sjslayjy
/
public_html
/
cropnet
/
app
/
Imports
/
Upload File
HOME
<?php namespace App\Imports; use Illuminate\Support\Collection; use Maatwebsite\Excel\Concerns\ToCollection; use Maatwebsite\Excel\Concerns\WithHeadingRow; use DB; class ImportMasterData implements ToCollection, WithHeadingRow { /** * @param Collection $collection * * */ public function collection(Collection $collection){ if(count($collection) >0){ // dd($collection); foreach($collection as $sheet){ $master =\DB::table('master')->where([['district_name','=',$sheet['district_name']],['district_code','=',$sheet['district_code']],['village_name','=',$sheet['village_name']],['village_code','=',$sheet['village_code']],['hamlet_name','=',$sheet['hamlet_name']],['hamlet_code','=',$sheet['hamlet_code']],['mcc_name','=',$sheet['mcc_name']],['mcc_code','=',$sheet['mcc_code']],['mpp_name','=',$sheet['mpp_name']],['mpp_code','=',$sheet['mpp_code']],['state_name','=',$sheet['state_name']],['state_code','=',$sheet['state_code']],['tehsil_name','=',$sheet['tehsil_name']],['tehsil_code','=',$sheet['tehsil_code']]])->where('is_active',1)->first(); $master_mpp =\DB::table('master')->where([['mpp_code','=',$sheet['mpp_code']]])->where('is_active',1)->first(); if(is_null($master) && is_null($master_mpp)){ \DB::table('master')->insert(['district_name' => $sheet['district_name'],'district_code' => $sheet['district_code'],'village_name' => $sheet['village_name'],'village_code' => $sheet['village_code'],'hamlet_name' => $sheet['hamlet_name'],'hamlet_code' => $sheet['hamlet_code'],'mcc_name' => $sheet['mcc_name'],'mcc_code' => $sheet['mcc_code'],'mpp_name' => $sheet['mpp_name'],'mpp_code' => $sheet['mpp_code'],'state_name' => $sheet['state_name'],'state_code'=> $sheet['state_code'],'tehsil_name' => $sheet['tehsil_name'],'tehsil_code' => $sheet['tehsil_code'],'created_by' => \Auth::user()->id ]); } } return true; }else{ return false; } } }