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 ] |
---|
<?php namespace App\Imports; use Auth; use App\Models\StudentEnroll; use App\Models\StudentAttendance; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Validator; use Maatwebsite\Excel\Concerns\ToCollection; use Maatwebsite\Excel\Concerns\WithHeadingRow; class AttendancesImport implements ToCollection, WithHeadingRow { protected $data; /** * @return void */ public function __construct($data) { $this->data = $data; } /** * @param array $row * * @return \Illuminate\Database\Eloquent\Model|null */ public function collection(Collection $rows) { Validator::make($rows->toArray(), [ '*.date' => 'required|date', '*.student_id' => 'required', '*.attendance' => 'required', ])->validate(); foreach ($rows as $row) { if($row['attendance'] == 'P'){$attendance = 1;} elseif($row['attendance'] == 'A'){$attendance = 2;} elseif($row['attendance'] == 'L'){$attendance = 3;} elseif($row['attendance'] == 'H'){$attendance = 4;} else{$attendance = 2;} $student_id = $row['student_id']; $subject = $this->data['subject']; // Enrolls $enroll = StudentEnroll::where('session_id', $this->data['session']); $enroll->with('student')->whereHas('student', function ($query) use ($student_id){ $query->where('student_id', $student_id); }); $enroll->with('subjects')->whereHas('subjects', function ($query) use ($subject){ $query->where('subject_id', $subject); }); $student = $enroll->first(); if(isset($student)){ // Attendance Update StudentAttendance::updateOrCreate( [ 'student_enroll_id' => $student->id, 'subject_id' => $this->data['subject'], 'date' => $row['date'], ],[ 'student_enroll_id' => $student->id, 'subject_id' => $this->data['subject'], 'date' => $row['date'], 'attendance' => $attendance, 'note' => $row['note'], 'created_by' => Auth::guard('web')->user()->id, ]); } } } }