CasperSecurity
<?php
namespace App\Imports;
use App\Models\EmployeeRegistration;
use App\Models\OdRequest;
use Carbon\Carbon;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class OdRequestImport implements ToModel,WithHeadingRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
//dd($row);
$empid = $row['employee_id'];
$hrdet=EmployeeRegistration::where('employee_id',$row['hr_id'])->first();
if($hrdet){
$hrid=$hrdet->id;
}
else{
$hrid="";
}
$manager=EmployeeRegistration::where('employee_id',$row['manager_id'])->first();
if($manager) {
$managerid = $manager->id;
}
else{
$managerid=null;
}
$od_from= Carbon::parse($row['od_from'])->format('Y-m-d');
$od_to = Carbon::parse($row['od_to'])->format('Y-m-d');
$empattendance= OdRequest::create([
'employee_id' => $row['employee_id'],
'req_id' => $row['req_id'],
'od_from' => $od_from,
'od_to' => $od_to,
'od_location' => $row['od_location'],
'od_reason' => $row['od_reason'],
'od_location' => $row['od_location'],
'hr_id'=>$hrid,
'manager_id'=>$managerid,
]);
}
}