Overview
TheGradeController allows teachers to view their courses, access enrolled students, and assign/update grades. All operations are restricted to teachers and include course ownership verification.
File Location: app/controllers/GradeController.php
Dependencies:
GrademodelCoursemodelAuthhelper
Methods
myCourses()
Displays all courses assigned to the logged-in teacher. Authorization: Teacher only Behavior:- Retrieves courses belonging to the authenticated teacher
- Renders teacher’s course listing view
app/views/grades/my_courses.php
students()
Displays all students enrolled in a specific course with their grades. Authorization: Teacher only (must own the course)Course ID (passed as route parameter)
- Verifies that the course belongs to the authenticated teacher
- Redirects to
/gradesif unauthorized
- Validates teacher owns the course
- Retrieves enrolled students and their grades
- Renders student listing view
app/views/grades/students.php
Response:
- Authorized: Renders student list with grades
- Unauthorized: Redirects to
/grades
save()
Saves or updates a student’s grade for a course. Authorization: Teacher only (must own the course)Student ID (POST request)
Course ID (POST request)
Grade value (POST request)
- Verifies teacher owns the course before saving grade
- Prevents teachers from grading other teachers’ courses
- Validates teacher authorization
- Verifies course ownership
- Saves/updates grade
- Redirects back to course student list
/grades/course?course_id={course_id}
Usage Examples
Viewing Teacher’s Courses
Viewing Students in a Course
Saving a Grade
Security Features
Course Ownership Verification
Before displaying students or saving grades, the controller verifies ownership:- Viewing students in other teachers’ courses
- Grading students in courses they don’t teach
Authorization Flow
Auth::teacher()- Ensures user is logged in as teacherbelongsToTeacher()- Verifies course ownership- Action execution - Only proceeds if both checks pass