77 lines
2.3 KiB
PHP
77 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Illuminate\Support\Collection;
|
|
use App\Models\courses;
|
|
use App\Models\Module;
|
|
use App\Models\StudentDetail;
|
|
use App\Models\CourseAssignStudent;
|
|
|
|
|
|
class MyCoursesController extends Controller
|
|
{
|
|
public function showMyCourses()
|
|
{
|
|
$userId = session('student_portal_log_id')
|
|
?? session('student_id')
|
|
?? session('id')
|
|
?? Auth::id();
|
|
|
|
$student = DB::table('student_details')
|
|
->where('student_portal_log_id', $userId)
|
|
->orWhere('id', $userId)
|
|
->orWhere('student_id', $userId)
|
|
->first();
|
|
|
|
if (!$student) {
|
|
return view('mycourse', [
|
|
'courses' => collect([]),
|
|
'student' => null
|
|
]);
|
|
}
|
|
|
|
// DB::table භාවිතයෙන් SQL join එක නිවැරදිව සිදු කිරීම
|
|
$courses = DB::table('courses')
|
|
->join('course_assign_student', 'courses.id', '=', 'course_assign_student.course_id')
|
|
->leftJoin('modules', 'courses.id', '=', 'modules.course_id') // <-- මේ පේළිය එකතු කරන ලදී
|
|
->whereIn('course_assign_student.student_id', array_filter([
|
|
$student->id ?? null,
|
|
$student->student_id ?? null,
|
|
$student->student_portal_log_id ?? null
|
|
]))
|
|
->select(
|
|
'courses.id as course_id',
|
|
'courses.title as course_title',
|
|
'courses.course_code',
|
|
'modules.id as module_id',
|
|
'modules.title as module_title',
|
|
'modules.description as module_description',
|
|
'modules.semester'
|
|
)
|
|
->get()
|
|
->groupBy('course_id');
|
|
|
|
return view('mycourse', compact('courses', 'student'));
|
|
}
|
|
|
|
// public function showModule($course_id)
|
|
// {
|
|
// $course = DB::table('courses')->where('id', $course_id)->first();
|
|
|
|
// if (!$course) {
|
|
// abort(404, 'Course not found');
|
|
// }
|
|
|
|
// $modules = DB::table('modules')
|
|
// ->where('course_id', $course_id)
|
|
// ->get();
|
|
|
|
// return view('module', compact('course', 'modules'));
|
|
// }
|
|
|
|
} |