|
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 App\Models\Biometric;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\ToArray;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use Maatwebsite\Excel\Concerns\Importable;
// use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithUpserts;
use Maatwebsite\Excel\Concerns\WithStartRow;
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
use Maatwebsite\Excel\Concerns\SkipsOnFailure;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithValidation;
class ImportBiometric implements ToArray, WithStartRow, WithValidation, WithHeadingRow, SkipsEmptyRows, SkipsOnFailure
{
use Importable;
public function startRow(): int
{
return 2;
}
public function rules(): array
{
return [
"personid" => "required",
"name" => "required",
"gender" => "required",
"date" => "required",
"check_in" => "required"
];
}
public function uniqueBy()
{
return 'PersonID';
}
public function array(array $array)
{
$finalAttLogs = array();
foreach ($array as $attlog) {
$check_in = preg_replace('/[^\p{L}\p{N}\s]/u', "", $attlog['check_in']);
if (!empty($check_in)) {
$ss = array(
"f_id" => $attlog['personid'],
"auth_datetime" => $attlog['date'] . " " . $attlog['check_in'],
"auth_date" => $attlog['date'],
"auth_time" => $attlog['check_in'],
"person" => $attlog['name'],
);
array_push($finalAttLogs, $ss);
}
}
DB::connection('mysql2')->table('attlogs')->insert($finalAttLogs);
}
public function onFailure(\Maatwebsite\Excel\Validators\Failure ...$failures)
{
dd($failures);
}
}