|
Server : Apache/2.4.41 (Ubuntu) System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 8.2.12 Disable Function : NONE Directory : /var/www/paras.theinteractive.in/app/Imports/ |
Upload File : |
<?php
namespace App\Imports;
use Illuminate\Support\Facades\DB;
use App\Models\Master;
use Maatwebsite\Excel\Concerns\ToModel;
use App\Models\State;
use App\Models\District;
use App\Models\Block;
use App\Models\Zila_panchayat;
use App\Models\School;
use App\Models\School_class;
class RegistrationsImport implements ToModel
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
array(
// 'id' => $row[0],
'state' => $row[1],
'discict' => $row[2],
'block' => $row[3],
'gp' => $row[4],
'type' => $row[5],
'school' => $row[6],
'class' => $row[7],
);
$checkState = State::where(['state'=>trim($row[1])])->first();
$stateId = '';
if(empty($checkState))
{
$statearr = array(
'state'=>trim($row[1]),
'status'=>'1',
'created_at'=>date('Y-m-d H:i:s')
);
$res = State::create($statearr);
$stateId = $res->id;
}else{
$stateId = $checkState->id;
}
if(!empty($stateId))
{
$checkDistrict = District::where(['state_id'=>$stateId,'district'=>trim($row[2])])->first();
$districtId = '';
if(empty($checkDistrict))
{
$statearr = array(
'state_id'=>$stateId,
'district'=>trim($row[2]),
'status'=>'1',
'created_at'=>date('Y-m-d H:i:s')
);
$res = District::create($statearr);
$districtId = $res->id;
}else{
$districtId = $checkDistrict->id;
}
}
if(!empty($stateId) && !empty($districtId))
{
$checkBlock = Block::where(['state_id'=>$stateId,'district_id'=>$districtId,'block'=>trim($row[3])])->first();
$blockId = '';
if(empty($checkBlock))
{
$statearr = array(
'state_id'=>$stateId,
'district_id'=>$districtId,
'block'=>trim($row[3]),
'status'=>'1',
'created_at'=>date('Y-m-d H:i:s')
);
$res = Block::create($statearr);
$blockId = $res->id;
}else{
$blockId = $checkBlock->id;
}
}
if(!empty($stateId) && !empty($districtId) && !empty($blockId))
{
$checkGP = Zila_panchayat::where(['state_id'=>$stateId,'district_id'=>$districtId,'block_id'=>$blockId,'name'=>trim($row[4])])->first();
$gpId = '';
if(empty($checkGP))
{
$statearr = array(
'state_id'=>$stateId,
'district_id'=>$districtId,
'block_id'=>$blockId,
'name'=>trim($row[4]),
'status'=>'1',
'created_at'=>date('Y-m-d H:i:s')
);
$res = Zila_panchayat::create($statearr);
$gpId = $res->id;
}else{
$gpId = $checkGP->id;
}
}
if(!empty($stateId) && !empty($districtId) && !empty($blockId) && !empty($gpId))
{
$checkSchool = School::where(['state_id'=>$stateId,'district_id'=>$districtId,'block_id'=>$blockId,'zilapanchayat_id'=>$gpId,'type'=>trim($row[5]),'name'=>trim($row[6])])->first();
$schoolId = '';
if(empty($checkSchool))
{
$statearr = array(
'state_id'=>$stateId,
'district_id'=>$districtId,
'block_id'=>$blockId,
'zilapanchayat_id'=>$gpId,
'type'=>trim($row[5]),
'name'=>trim($row[6]),
'status'=>'1',
'created_at'=>date('Y-m-d H:i:s')
);
$res = School::create($statearr);
$schoolId = $res->id;
}else{
$schoolId = $checkSchool->id;
}
}
/* if(!empty($stateId) && !empty($districtId) && !empty($blockId) && !empty($gpId) && !empty($schoolId))
{
// $checkSchool = School_class::where(['school_id'=>$schoolId,'class'=>trim($row[7])])->first();
$classes = explode(',',trim($row[7]));
$checkClass = School_class::whereIn('class',$classes)->where('school_id',$schoolId)->get();
$count = $checkClass->count();
// $classId = '';
$_classarr = array();
if($count < 1)
{
foreach($classes as $classe)
{
$classArr = array(
'school_id'=>$schoolId,
'class'=>trim($classe),
'status'=>'1',
'created_at'=>date('Y-m-d H:i:s')
);
array_push($_classarr,$classArr);
}
School_class::insert($_classarr);
}
} */
}
}