/
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 MppImport implements ToCollection, WithHeadingRow { /** * @param Collection $collection * * */ public function collection(Collection $collection){ if(count($collection) >0){ foreach($collection as $sheet){ $mpp =\DB::table('mpp')->where([['code','=',$sheet['mpp_code']],['name','=',$sheet['mpp_name']],['mcc_code','=',$sheet['mcc_code']]])->first(); if(is_null($mpp)){ $assinged_data = \DB::table('assign_users')->where('mcc_code', $sheet['mcc_code'])->get(); if(count($assinged_data) >0) { foreach($assinged_data as $ad){ $mppArr = explode(',', $ad->mpp_code); if(!in_array($sheet['mpp_code'], $mppArr)) { \DB::table('assign_users')->where('user_id', $ad->user_id)->where('mcc_code', $ad->mcc_code)->update([ 'mpp_code' => $ad->mpp_code.','.$sheet['mpp_code'], ]); } } } \DB::table('mpp')->insert([ 'code' => $sheet['mpp_code'], 'name' => $sheet['mpp_name'], 'mcc_code' => $sheet['mcc_code'], ]); } } return true; }else{ return false; } } }