Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jasd's avatar
Level 1

Student wants to enroll a Course. Form validation, Entity validation, etc.

So I am building a web app where Students can enroll courses.

I have a course and student objects.

When Student presses "Enroll" button a POST request to a CourseController is done. In the CourseController I validate that the course id exists through Form validation (exists).

Where would I put logic stuff like Student has more than 20 points or other "Model prequesties", would I use commands? add special form validation rules, use a service?

Any ideas?

0 likes
3 replies
davidfaux's avatar

If the student in this overview is already authenticated wouldn't it make more sense to check if they have the required points before displaying the enrolment form?

if($student->points() > $course->min_points)
{
    return view('course.enrole', compact('student', 'course');
}

//Set notification that they do not have the minimum points etc.
return redirect()->route('home');

You could even disable the hyperlinks point to the enrolment pages based on minimum points using some sort of presenter. Besides points, if there are a number of criteria that would prevent or allow a student to enrol I would rather check those before and then, once the form is submitted, check them again using an "Enrolement" class that would validation non-form driven values, e.g. minimum points etc.

1 like

Please or to participate in this conversation.