Back | Home
الـ Path الحالي: /home/picotech/domains/instantly.picotech.app/public_html/vendor/voku/.././maatwebsite/excel/src
الملفات الموجودة في هذا الـ Path:
.
..
Cache
Cell.php
ChunkReader.php
Concerns
Console
DefaultValueBinder.php
DelegatedMacroable.php
Events
Excel.php
ExcelServiceProvider.php
Exceptions
Exporter.php
Facades
Factories
Fakes
Files
Filters
HasEventBus.php
HeadingRowImport.php
Helpers
Importer.php
Imports
Jobs
MappedReader.php
Mixins
QueuedWriter.php
Reader.php
RegistersCustomConcerns.php
Row.php
SettingsProvider.php
Sheet.php
Transactions
Validators
Writer.php

مشاهدة ملف: MappedReader.php

<?php

namespace Maatwebsite\Excel;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToArray;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;
use Maatwebsite\Excel\Concerns\WithFormatData;
use Maatwebsite\Excel\Concerns\WithMappedCells;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class MappedReader
{
    /**
     * @param  WithMappedCells  $import
     * @param  Worksheet  $worksheet
     *
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     */
    public function map(WithMappedCells $import, Worksheet $worksheet)
    {
        $mapped = [];
        foreach ($import->mapping() as $name => $coordinate) {
            $cell = Cell::make($worksheet, $coordinate);

            $mapped[$name] = $cell->getValue(
                null,
                $import instanceof WithCalculatedFormulas,
                $import instanceof WithFormatData
            );
        }

        if ($import instanceof ToModel) {
            $model = $import->model($mapped);

            if ($model) {
                $model->saveOrFail();
            }
        }

        if ($import instanceof ToCollection) {
            $import->collection(new Collection($mapped));
        }

        if ($import instanceof ToArray) {
            $import->array($mapped);
        }
    }
}