How I built my Capstone Project with Laravel and MySQL

Nishant Phour
6 min readNov 17, 2020

The project was online examination system named as HomeExam. It was my capstone project for 7th semester at Bennett University. This project as the name suggests, provides platforms to both students and instructors to conduct online exams from anywhere.

This Online Examination System is a technological solution that can be used to organize, administer, and handle exams in an online environment for any school, sector or institute. The Internet/Intranet and/or Local Area Networks may be used. There are several problems faced during manual examinations system. Delays may occur in result processing. Filtering of records is difficult. Also, these systems are difficult to maintain and takes lot of time and effort. But Online Examination will be much more efficient, fast and reduce the high amount of material cost. It is a web-based project. The effective use of Online Examination System for any Educational Institute or training centers can be use it to develop their strategy for putting the exams, and for getting better results in less time.

Why HomeExam?

For analysts and educators, directing examination is often highly repetitive work in the normal context. After the test, the whole process of allocating exam and measuring their score was physically conducted until date. Be that as it may, the system for online research is completely electronic. The framework aims to minimize expenditure associated with performing examinations over a timeframe and full computerization of examination framework-related activities such as enlistment, distribution of outcomes, prompting a high degree of effectiveness of the framework. In the wake of experiencing enormous numbers of reference documents, we are finally concluded that we can produce one examination system that can provide easy access to create for guiding examination and investigation of result.

Technologies: I have used HTML, CSS and JavaScript as frontend and PHP and MySQL as Backend. I also used Laravel Framework.

Basic Working

User Interface of my software is very user-friendly. System will have three different user roles i.e. students, instructors and admin. The system will facilitate online examination as well as the documentation of results. The instructor can conduct several examinations for different subjects. It also deals with enrollment or registration of students, submission of registration forms and issuing unique user-id and password to enrolled students. Admin can add students and instructors to the system with their unique id and password which they can change later. Admin has also the power to delete or edit the users. Admin can monitor all the activities performed by both students and instructors. Instructor can add subjects and create exams for particular subject. They can customize the exam like set date and time of exam, can add questions.

Installing and Creating a Laravel 5.7 Project

In this section we’ll introduce Laravel and then proceed it to install and create a Laravel 5.7 project.

About Laravel

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel is accessible, yet powerful, providing tools needed for large, robust applications.

In your terminal, run the following command to generate a laravel 5.7 project:

$ composer create-project — prefer-dist laravel/laravel new-app

This command will install latest laravel version.

Verify installed version by:

$ cd laravel-first-crud-app 
$ php artisan -V
Laravel Framework 5.7.22

Front-end Dependencies:

Use npm to install the front-end dependencies:

$ npm install

After running this command a node_modules folder will be created and the dependencies will be installed into it.

Creating a MySQL Database

To create MySql database in terminal run the following to run the mysql client:

$ mysql -u root -p

then enter the password for your MySQL server after installing it.

Next, run this SQL statement to create a database:

mysql> create database db;

Open the .env file and update the credentials to access your MySQL database:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db
DB_USERNAME=root
DB_PASSWORD=******

Run the migrate command to create your database and all the SQL tables needed by Laravel.

Now, let’s create our first Laravel Model. In your terminal, run the following command:

$ php artisan make:model Contact --migration

This will create a Contact model and a migration file. In the terminal, we get an output similar to:

Model created successfully. 
Created Migration: 2019_01_27_193840_create_contacts_table

Now you can create the contacts table in the database with the help of the following command

$ php artisan migrate

Implementing the CRUD Operations

Let’s now implement the controller methods alongside the views.

C: Implementing the Create Operation and Adding a Form

The ContactController includes

  • A store() method that maps to an endpoint of the POST /contacts API that will be used to establish a database contact.
  • Create() which maps the GET /contacts/create route used to serve the HTML form used to send the contact to the endpoint of the POST /contacts API.

Let’s implement these two methods.

In the app/Http/Controllers/ContactController.php file and import the contact model

use App\Contact;

Next, locate the store() method and update it accordingly:

public function store(Request $request)
{
$request->validate([
'first_name'=>'required',
'last_name'=>'required',
'email'=>'required'
]);
$contact = new Contact([
'first_name' => $request->get('first_name'),
'last_name' => $request->get('last_name'),
'email' => $request->get('email'),
'Semester' => $request->get('Semester'),
'Course' => $request->get('Course'),
'Course' => $request->get('Course')
]);
$contact->save();
return redirect('/contacts')->with('success', 'Contact saved!');
}

Next, create the template

$ cd contacts 
$ touch create.blade.php

Open the resources/views/contacts/create.blade.php file and add the following code:

@extends('base')@section('main')
<div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Add a contact</h1>
<div>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div><br />
@endif
<form method="post" action="{{ route('contacts.store') }}">
@csrf
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" class="form-control" name="first_name"/>
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" class="form-control" name="last_name"/>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" name="email"/>
</div>
<div class="form-group">
<label for="city">City:</label>
<input type="text" class="form-control" name="city"/>
</div>
<div class="form-group">
<label for="country">Country:</label>
<input type="text" class="form-control" name="country"/>
</div>
<div class="form-group">
<label for="job_title">Job Title:</label>
<input type="text" class="form-control" name="job_title"/>
</div>
<button type="submit" class="btn btn-primary-outline">Add contact</button>
</form>
</div>
</div>
</div>
@endsection

This is a screenshot of our create form!

Similarly create all the pages and your project will be ready :-) .

Conclusion

The aim of the online exam system discussed in this paper is to establish a smart, effective, safe and reliable system of paperless exams, which is the unity of instruction and test. With the set in question selecting the form, the system can accommodate different disciplines, teaching, test, which plays a major role in the process of testing, teaching Method and outstanding course building as well as minimizing the function of teachers and administrative educational personnel boost the learning time of students and easily ask about the scores.

--

--