MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/celkcksm/demo.ncriptech.com/../cms.ncriptech.com/app/Imports/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/demo.ncriptech.com/../cms.ncriptech.com/app/Imports/SubjectsImport.php
<?php

namespace App\Imports;

use App\Models\Subject;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class SubjectsImport implements ToCollection, WithHeadingRow
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function collection(Collection $rows)
    {
        Validator::make($rows->toArray(), [
            '*.title' => 'required|max:191|unique:subjects,title',
            '*.code' => 'required|max:191|unique:subjects,code',
            '*.credit_hour' => 'required|numeric',
            '*.subject_type' => 'nullable|integer',
            '*.class_type' => 'required|integer',
        ])->validate();


        foreach ($rows as $row) {
            Subject::updateOrCreate(
                [
                'code'    => $row['code'],
                ],[
                'title'    => $row['title'],
                'code'    => $row['code'],
                'credit_hour'    => $row['credit_hour'],
                'subject_type'    => $row['subject_type'] ?? 0,
                'class_type'    => $row['class_type'],
            ]);
        }
    }
}

MMCT - 2023