@extends('admin.admin_dashboard') @section('admin')
{{-- Page title (compact) --}}
Bulk Subject Mapping
Assign subjects to multiple students at once
@if(session('error'))
{{ session('error') }}
@endif @if(session('success'))
{{ session('success') }}
@endif {{-- Filter Card (compact) --}}
Filter
Select session & class
{{-- Students --}} @if($students->isNotEmpty())
@csrf
Students: {{ $students->count() }} @if($classCode <= 8) Class {{ $classCode }}: Regular @else Class {{ $classCode }}: Main + 4th @endif
@if($classCode <= 8) @else @endif @if($classCode <= 8) @else @endif @if($classCode > 8) @endif @foreach($students as $index => $registration) @php $student = $registration->student; $studentMappings = $existingMappings->get($student->id, collect()); $hasExisting = $studentMappings->isNotEmpty(); // ✅ Filter subjects based on student's group and religion (case-insensitive) $studentGroupId = $registration->group_id; $studentReligion = !empty($student->religion) ? strtolower(trim($student->religion)) : 'islam'; // Check if subjects are GroupSubject objects (has group_id property) $firstItem = $subjects->first(); $hasGroupProperty = $firstItem && property_exists($firstItem, 'group_id'); // Apply religion filter function $applyReligionFilter = function($subjectItem) use ($studentReligion) { // Handle both Subject object and GroupSubject object $subject = is_object($subjectItem) && property_exists($subjectItem, 'subject') ? $subjectItem->subject : $subjectItem; if (empty($subject->religion)) { return true; // Common subject - show to all } return strtolower(trim($subject->religion)) === $studentReligion; }; // For class > 8 and no specific group filter if ($classCode > 8 && !$selectedGroup && $hasGroupProperty) { // Filter by student's group first, then by religion $filteredSubjects = $subjects ->where('group_id', $studentGroupId) ->filter($applyReligionFilter) ->map(fn($gs) => $gs->subject) ->filter() ->sortBy('order_by') ->values(); } else { // For class <= 8 or when specific group is selected $filteredSubjects = $subjects->filter($applyReligionFilter)->sortBy('order_by')->values(); } @endphp {{-- Per student toggle (All) --}} @if($classCode <= 8) @else {{-- MAIN --}} {{-- FOURTH (MULTIPLE ALLOWED) --}} @endif @endforeach
SL Student Roll All
Subjects Default selected (if new)
Subjects Main default (if new) • 4th optional (multiple)
Main Default (if new) 4th Optional Multiple
{{ $index + 1 }}
{{ $student->student_name_english ?? 'N/A' }}
@if($registration->group) {{ $registration->group->name }} @endif @if($registration->section) {{ $registration->section->name }} @endif
{{ $registration->class_roll ?? 'N/A' }}
@foreach($filteredSubjects as $subject) @php $rid = "r_{$student->id}_{$subject->id}"; $mapped = $studentMappings->firstWhere('subject_id', $subject->id); $isChecked = $hasExisting ? (bool)$mapped : true; // ✅ FIX @endphp
@endforeach
@foreach($filteredSubjects as $subject) @php $mid = "m_{$student->id}_{$subject->id}"; $mapped = $studentMappings->firstWhere('subject_id', $subject->id); $isMainChecked = $hasExisting ? ($mapped && $mapped->is_main) : true; // ✅ FIX @endphp
@endforeach
@foreach($filteredSubjects as $subject) @php $fid = "f_{$student->id}_{$subject->id}"; $mapped = $studentMappings->firstWhere('subject_id', $subject->id); $isFourthChecked = $hasExisting ? ($mapped && $mapped->is_fourth) : false; // ✅ MULTI OK @endphp
@endforeach
@elseif($selectedSession && $selectedClass)
No students found

Please check your filter criteria or try different options.

@else
Please select Session and Class to view students

Use the filter options above to load student data.

@endif
@endsection @section('customjs') @endsection