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/demoadmin.ncriptech.com/../cms.ncriptech.com/app/Imports/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php namespace App\Imports; use Auth; use App\Models\Student; use App\Models\StudentAssignment; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Validator; use Maatwebsite\Excel\Concerns\ToCollection; use Maatwebsite\Excel\Concerns\WithHeadingRow; class AssignmentMarksImport 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(), [ '*.student_id' => 'required', '*.marks' => 'nullable|numeric', ])->validate(); foreach ($rows as $row) { $student = Student::where('student_id', $row['student_id'])->first(); StudentAssignment::where('student_enroll_id', $student->currentEnroll->id) ->where('assignment_id', $this->data['assignment']) ->update([ 'attendance' => $row['attendance'] ?? null, 'date' => $row['date'] ?? null, 'marks' => $row['marks'] ?? null, 'updated_by' => Auth::guard('web')->user()->id, ]); } } }