Overview
The Enrollment model manages the relationship between students and courses, handling enrollment operations and queries. File:app/models/Enrollment.php
Methods
getAll
Retrieves all enrollments with student and course information. SQL Query:Returns array of all enrollments with related data
create
Creates a new enrollment for a student in a course.ID of the student to enroll
ID of the course to enroll in
Returns
true if enrollment was successful, false otherwiseUse
isAlreadyEnrolled() before creating to prevent duplicate enrollments.delete
Deletes an enrollment for a specific student and course.Student ID
Course ID
No return value (throws exception on failure)
getByStudent
Retrieves all enrollments for a specific student.Student ID to filter by
Returns array of enrollment records for the student
isAlreadyEnrolled
Checks if a student is already enrolled in a specific course.Student ID to check
Course ID to check
Returns
true if student is already enrolled, false otherwiseThis method is useful for preventing duplicate enrollments before calling
create().