%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/silvzytp/calling_code/app/Imports/
Upload File :
Create Path :
Current File : /home/silvzytp/calling_code/app/Imports/CallingImport.php

<?php

namespace App\Imports;

use App\Models\Colling;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class CallingImport implements ToCollection, WithHeadingRow
{
    protected $fileName;

    public function __construct($fileName)
    {
        $this->fileName = $fileName;
    }

    /**
    * @param Collection $collection
    */
    public function collection(Collection $rows)
    {

        $i = 1;
        $data = [];
        foreach($rows as $row){
            $calling = Colling::orderBy('id','desc')->first();
            if ($calling) {
                $increment = PREFIX . $calling->id+$i;
            }else{
                $increment = PREFIX . $i;
            }

            $em1=trim($row['name']);

            $em = collect([$em1]);
            
            if($em->filter()->isNotEmpty()){
                $data[] = [
                    'file_name'       => (string)$this->fileName,
                    'serial'          => $increment,
                    'name'            => (string)$row['name'],
                    'email'           => (string)$row['email'],
                    'phone'           => (string)$row['phone'],
                    'number_1'        => (string)$row['number1'],
                    'number_2'        => (string)$row['number2'],
                    'import_date'     => date('Y-m-d'),
                    'created_at'      => date('Y-m-d'),
                    'updated_at'      => date('Y-m-d'),
                    'import_id'       => auth()->user()->id
                ];
            }

            $i++;
        }

        Colling::insert($data);
    }
}

Zerion Mini Shell 1.0