A portfolio REST API built with Laravel 8, demonstrating a relational domain model across three entities, resource-based routing, standardised JSON response patterns, and token authentication via Laravel Passport.
The API models an educational platform built around three core entities and their relationships:
Teacher
└── has many Periods
└── has many Students
Each entity supports full CRUD operations through dedicated controllers and API Resources. The relational structure reflects a real-world educational system — a teacher owns multiple class periods, each period enrolls multiple students — making this a meaningful demonstration of Eloquent relationships and layered architecture beyond single-table CRUD.
- Relational domain model — Teacher → Period → Student across 3 Eloquent models with defined relationships
- API Resources — consistent JSON response shaping via
PeriodResource,TeacherResource,StudentResource - Standardised response layer — base
sendResponse()andsendError()helpers for uniform API output across all endpoints - Input validation — Laravel
Validatorclass used at the controller level before any persistence logic - Token authentication — Laravel Passport integrated for API token-based registration and login
- RESTful routing — clean resource routes via
Route::apiResource()across all three domains - Environment-based configuration —
.env.exampleprovided for straightforward local setup
- PHP 7.3 / 8.0
- Laravel 8
- Laravel Passport
- Eloquent ORM
- MySQL / SQLite
- Guzzle 7
# 1. Clone the repository
git clone https://github.com/DannyBoyIL/BrainPOP.git
cd BrainPOP
# 2. Install dependencies
composer install
# 3. Configure environment
cp .env.example .env
php artisan key:generate
# 4. Set up database (update DB_* in .env first)
php artisan migrate
# 5. Install Passport keys
php artisan passport:install
# 6. Start the server
php artisan serveAPI available at: http://localhost:8000/api
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/register |
Register a new user |
| POST | /api/login |
Login and receive token |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/teachers |
List all teachers |
| POST | /api/teachers |
Create a teacher |
| GET | /api/teachers/{id} |
Get a teacher |
| PUT | /api/teachers/{id} |
Update a teacher |
| DELETE | /api/teachers/{id} |
Delete a teacher |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/periods |
List all periods |
| POST | /api/periods |
Create a period |
| GET | /api/periods/{id} |
Get a period |
| PUT | /api/periods/{id} |
Update a period |
| DELETE | /api/periods/{id} |
Delete a period |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/students |
List all students |
| POST | /api/students |
Create a student |
| GET | /api/students/{id} |
Get a student |
| PUT | /api/students/{id} |
Update a student |
| DELETE | /api/students/{id} |
Delete a student |
All responses follow a consistent envelope via the base response helpers:
Success:
{
"success": true,
"data": { ... },
"message": "Period updated successfully."
}Error:
{
"success": false,
"message": "Validation Error.",
"data": {
"name": ["The name field is required."]
}
}Validation is handled at the controller level using Laravel's Validator class before any update or persistence logic runs:
public function update(Request $request, Period $period): JsonResponse
{
$validator = Validator::make($request->all(), [
'name' => 'required'
]);
if (!$validator->fails()) {
if ($period->update($request->all())) {
return $this->sendResponse(new PeriodResource($period), 'Period updated successfully.');
}
}
return $this->sendError('Validation Error.', $validator->errors());
}Laravel's FormRequest classes are the idiomatic approach for larger applications. This project uses Validator::make() directly to keep the validation logic visible and explicit within the controller — making the flow easier to follow and the design decisions easier to discuss.
app/
├── Http/
│ ├── Controllers/API/ # Resource controllers (Teacher, Period, Student, Auth)
│ └── Resources/ # API Resource transformers
├── Models/ # Eloquent models with relationships
└── Providers/ # Service providers including Passport
database/
├── migrations/ # Schema definitions for all three entities
└── seeders/ # Development seed data
routes/
└── api.php # RESTful API route definitions
Daniel Lotem — github.com/DannyBoyIL · linkedin.com/in/daniel-lotem