Skip to main content
Home About Portfolio
Web Development

How to Build a Laravel LMS and Online Exam Portal

Build a dependable Laravel learning platform with question banks, server-controlled exam timing, recoverable answers, grading, and accessible student workflows.

Md Shafin Ahmed

Md Shafin Ahmed

Full-Stack Developer

6 minute read · Tutorial
How to Build a Laravel LMS and Online Exam Portal

A learning platform should help a student resume a lesson, complete an assessment, and understand the result without guessing what happened. This tutorial develops an illustrative Laravel 9 and PHP 8.1 design, not private client source. NTCBD LMS includes MCQ, SATA, matrix, and drag-and-drop assessment formats; those requirements explain why a simple questions table is rarely enough.

1. Map the learning journey before the tables

Write one complete scenario: a student enrols, opens a course, studies a lesson, starts an eligible exam, saves answers, submits, and reviews permitted feedback. Mark every decision that requires a permission check. Decide whether an expired enrolment blocks new attempts, existing attempts, or both. These are product rules, not details to leave to the browser.

Separate courses, lessons, enrolments, exams, question versions, attempts, and answers. Keep enrolment history rather than overwriting evidence of access. Assign an owner to each administrative action and record important changes. Sketch the relationships with sample records before building screens, especially where one question appears in several assessments with different marking rules.

Conceptual illustration of lessons, question banks, and a timed Laravel examination workspace
Conceptual illustration: the learning journey connects lessons, assessments, and results; this is not an application screenshot.

2. Version questions and define marking precisely

Store the wording, options, correct responses, and grading configuration as an immutable question version when an exam is published. An attempt should reference that version, so an instructor fixing tomorrow's question does not silently change yesterday's result. Validate imported questions in a preview stage before making them available to learners.

For single-answer MCQ, define whether unanswered responses earn zero and whether incorrect answers lose marks. For SATA, specify exact-match or partial-credit scoring explicitly. Matrix questions need stable row and column identifiers; drag-and-drop questions need stable item and target identifiers. Offer a keyboard-accessible alternative. Never send answer keys to the learner before the review policy permits disclosure.

3. Make the server own timing and access

Create attempts only after checking enrolment, scheduling, allowed attempt count, and prerequisites. Derive the student identity from authentication. Calculate the deadline on the server from the exam window and allowed duration, then persist it. The visible countdown is a convenience; changing a device clock must never extend the assessment.

The following answer-save fragment assumes an authenticated controller, a registered attempt policy, a validated request, datetime casts, and an answer relationship. The policy verifies ownership and course access. Add a unique database constraint on the attempt and question pair. Use the same locked attempt row for final submission so saving and submitting cannot race each other.

use App\Models\Attempt;
use Illuminate\Support\Facades\DB;

$this->authorize('update', $attempt);
$data = $request->validate([
    'question_id' => ['required', 'integer'],
    'response' => ['required', 'array', 'max:100'],
]);

DB::transaction(function () use ($attempt, $data) {
    $locked = Attempt::whereKey($attempt->id)->lockForUpdate()->firstOrFail();
    abort_unless($locked->status === 'in_progress', 409);
    abort_if(now()->greaterThanOrEqualTo($locked->expires_at), 409);
    $question = $locked->exam->questions()
        ->whereKey($data['question_id'])->firstOrFail();
    // Validate response identifiers against this question's immutable version.
    $response = app(AnswerValidator::class)->validate($question, $data['response']);
    $locked->answers()->updateOrCreate(
        ['question_id' => $question->id],
        ['response' => $response]
    );
});

4. Design answer saving for unreliable connections

Save after a meaningful change and display a clear saving, saved, or retry state. Include a server-confirmed save time rather than suggesting that typing automatically means persistence. Debounce frequent changes, but flush pending work before navigation. Make repeat saves idempotent so a retry updates an existing answer instead of creating duplicates.

When multiple tabs are possible, choose a conflict strategy. A monotonically increasing answer revision can reject stale updates, while a single active attempt session simplifies support. Document what happens when connectivity returns after the deadline. Any grace period must be a consistent server rule, not an undocumented client exception. Do not store answer keys in offline storage.

5. Finalise once and grade reproducibly

Finalisation should lock the attempt, check its state, freeze accepted answers, and mark submission once. A repeated submit request should return the existing outcome. Decide how an expired attempt is finalised by a scheduled process when the student never presses submit. Record whether submission was voluntary or automatic so support can explain it.

Keep grading functions deterministic and test them independently of controllers. The example below demonstrates exact-match SATA grading, not partial credit. Store marks as integer units when fractional scores are needed, and document the unit. Save a grading version with the result so a later algorithm change can be reviewed rather than quietly altering historical scores.

function exactMatchUnits(array $selected, array $correct, int $available): int
{
    $normalise = static function (array $values): array {
        $values = array_values(array_unique(array_map('strval', $values)));
        sort($values, SORT_STRING);
        return $values;
    };

    return $normalise($selected) === $normalise($correct) ? $available : 0;
}

// Example unit: 100 units = one mark. Identifiers must be validated first.
assert(exactMatchUnits(['b', 'a'], ['a', 'b'], 100) === 100);
assert(exactMatchUnits(['a'], ['a', 'b'], 100) === 0);
Conceptual illustration of protected lesson video alongside learning progress
Conceptual illustration: protected video lessons complement assessments without exposing private course files.

6. Build review screens around useful feedback

Show the attempt status, accepted submission time, earned marks, and topic-level feedback before adding decorative charts. Explain whether solutions appear immediately, after the exam window closes, or only with instructor approval. This prevents a learner from assuming that hidden feedback means missing data. Use plain language for partial credit and penalties.

Allow instructors to investigate a disputed answer using the immutable question, saved response, and grading rule. Restrict student identifiers in exports and authorise report downloads. Avoid public result URLs containing predictable record identifiers without access checks. A student should only see another learner's information when an explicit, consent-aware product requirement actually permits it.

7. Test failure paths as carefully as success

Write feature tests for another student's attempt, an unenrolled account, an expired deadline, a duplicate submission, and an answer referencing a different exam. Freeze time in tests to make boundary behaviour repeatable. Exercise the final second before expiry and the exact deadline rather than testing only obviously early and late requests.

Test slow networks, browser refreshes, keyboard navigation, long question wording, and image alternatives on a real phone. Review database indexes for student attempt history and pending finalisation queries. Queue notifications after committed changes, and keep notification failures separate from successful exam submission. A failed email must not make the interface claim that an accepted attempt was lost.

8. Launch with an operational checklist

Before opening enrolment, run a small rehearsal using separate student and instructor accounts. Restore a backup in a nonproduction environment and verify that answers and question versions remain linked. Assign responsibility for failed queues, storage capacity, and scheduled expiry processing. Publish a support process for interrupted exams instead of improvising rules during a live assessment.

  • Confirm server time and timezone handling.
  • Verify policies on every attempt and report route.
  • Rehearse interrupted saving and repeated submission.
  • Review accessible alternatives for interactive questions.
  • Record recovery and grading correction procedures.
Md Shafin Ahmed

Written by

Md Shafin Ahmed

Laravel, Wix & Flutter developer at HEXBRID, building custom web applications, e-commerce stores, and mobile apps for growing businesses.

More About Me
Keep Reading

Related Insights

All Articles

Have a project in mind?

Let's build a Laravel web application, Flutter mobile app, or Wix and WordPress store—with APIs, technical SEO, and deployment support.

Start A Conversation