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.
58 lines
1.6 KiB
58 lines
1.6 KiB
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use App\Models\ParkingPattern;
|
|
use App\Services\OperationLogService;
|
|
use App\Services\ParkingPatternService;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Maatwebsite\Excel\Concerns\ToModel;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
|
|
class ParkingPatternImport implements ToModel
|
|
{
|
|
protected string $model_name;
|
|
protected string $en_name;
|
|
protected string $tw_name;
|
|
protected string $user_id;
|
|
protected int $index = 1;
|
|
|
|
public function __construct(
|
|
string $model_name,
|
|
string $user_id,
|
|
string $en_name = '',
|
|
string $tw_name = ''
|
|
) {
|
|
$this->model_name = $model_name;
|
|
$this->en_name = $en_name ?? '';
|
|
$this->tw_name = $tw_name ?? '';
|
|
$this->user_id = $user_id;
|
|
}
|
|
|
|
/**
|
|
* @param array $row
|
|
*/
|
|
public function model(array $row)
|
|
{
|
|
if ($this->index == 1) {
|
|
$this->index += 1;
|
|
return;
|
|
}
|
|
if (!empty($row[1])
|
|
&& !empty($row[2])
|
|
) {
|
|
$data = [
|
|
'model_name' => $this->model_name,
|
|
'admin_user_id' => $this->user_id,
|
|
'parking_space_number' => $row[1],
|
|
'parking_space_type' => $row[2],
|
|
'en_name' => $this->en_name,
|
|
'tw_name' => $this->tw_name
|
|
];
|
|
$service = new ParkingPatternService(new OperationLogService());
|
|
$service->saveModel($data);
|
|
}
|
|
}
|
|
}
|
|
|