Mahdee Rajon
File "AccountImport.php"
Full Path: /var/www/html/back/app/Imports/AccountImport.php
File size: 972 bytes
MIME-type: text/x-php
Charset: utf-8
<?php
namespace App\Imports;
use App\Models\Account;
use App\Models\Organization;
use Carbon\Carbon;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;
class AccountImport implements ToModel, WithStartRow
{
public function startRow(): int
{
return 2;
}
public function model(array $row)
{
if (isset($row[8])) {
$organization = Organization::query()->firstOrCreate(['model_id' => 3, 'full_name' => $row[8]]);
}
if (isset($row[11]) == 'Да') {
$archive = true;
}
return new Account([
'model_id' => 3,
'name' => $row[0],
'number' => $row[1],
'balance_of_the_date' => $row[2],
'organization_id' => $organization->id ?? null,
'archived' => $archive ?? false,
'added' => Carbon::parse($row[3])->format('Y-m-d'),
'deposit' => 0
]);
}
}