You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use App\Models\ParkingLicensePlate;
|
|
use App\Services\OperationLogService;
|
|
use Maatwebsite\Excel\Concerns\ToModel;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
|
|
class ParkingLicensePlateImport implements ToModel, WithHeadingRow
|
|
{
|
|
protected string $parkingSpaceType;
|
|
|
|
/**
|
|
* @var OperationLogService
|
|
*/
|
|
private OperationLogService $logService;
|
|
|
|
public function __construct($parking_space_type)
|
|
{
|
|
$this->logService = new OperationLogService();
|
|
$this->logService->menuTitle = 'cat_attr';
|
|
$this->parkingSpaceType = $parking_space_type;
|
|
}
|
|
|
|
/**
|
|
* @param array $row
|
|
*/
|
|
public function model(array $row)
|
|
{
|
|
$data = [];
|
|
foreach ($row as $value) {
|
|
$data[] = $value;
|
|
}
|
|
$where = [
|
|
'number' => $data[0],
|
|
'space_type_id' => $this->parkingSpaceType
|
|
];
|
|
if (!ParkingLicensePlate::query()->where($where)
|
|
->exists()
|
|
) {
|
|
$model = new ParkingLicensePlate([
|
|
'number' => $data[0],
|
|
'space_type_id' => $this->parkingSpaceType,
|
|
'created_at' => get_datetime()
|
|
]);
|
|
$this->logService->logCreated($model, 'license_plate.create');
|
|
}
|
|
}
|
|
}
|
|
|