Car Park Booking API
A Laravel 12 REST API for managing car park bookings with seasonal pricing and token-based authentication
Project Overview
Purpose
The Car Park Booking API is a comprehensive REST API built with Laravel 12 that enables efficient management of car park bookings. It provides a flexible pricing system with seasonal variations, secure authentication, and complete booking lifecycle management.
Challenge
Design and implement a scalable API that handles complex pricing rules (summer/winter rates, weekday/weekend variations), manages capacity constraints, and provides secure user authentication while maintaining clean, testable code architecture.
Solution
Built a RESTful API using Laravel 12 with PHP 8.2, implementing Laravel Sanctum for token-based authentication. Created a flexible pricing engine that handles seasonal variations, developed comprehensive CRUD operations for bookings, and included public endpoints for price calculations and availability checks. Utilized SQLite for development with support for production databases, and implemented a complete Pest test suite for quality assurance.
Key Features
Seasonal Pricing Engine
Configurable pricing rules supporting summer/winter rates and weekday/weekend variations. Prices stored in pence internally for precision, with capacity and pricing evaluated per calendar day.
Token-Based Authentication
Secure authentication using Laravel Sanctum with user registration, login, logout, and profile management. Includes seeded demo accounts for both admin and customer roles.
Comprehensive Booking Management
Full CRUD operations for bookings including list, create, update, and delete functionality. Automatic availability checking and capacity management per calendar day.
Public API Endpoints
Public endpoints for price calculation and availability checking, allowing integration with external systems without authentication. Includes Postman collection for easy testing.
Comprehensive Test Suite
Built with Pest testing framework for robust quality assurance. Includes unit and feature tests ensuring reliability across all API endpoints and business logic.
Flexible Database Support
SQLite for development with seamless support for MySQL, PostgreSQL, and other Laravel-compatible databases in production environments.
Technology Stack
Backend & Framework
-
▹
Laravel 12
Modern PHP framework providing robust API foundation
-
▹
PHP 8.2
Latest PHP features for type safety and performance
-
▹
Laravel Sanctum
Token-based authentication for API security
-
▹
Composer
Dependency management for PHP packages
Database & Testing
-
▹
SQLite
Development database with production database support
-
▹
Pest
Modern testing framework for comprehensive test coverage
-
▹
Eloquent ORM
Laravel's database abstraction layer
Development Tools
-
▹
Postman Collection
Pre-configured API testing collection
-
▹
Git
Version control and source code management
API Endpoints
Public Endpoints
-
▹
GET /api/price
Calculate booking price for specified dates
-
▹
GET /api/availability
Check availability for specified dates
Authentication Endpoints
-
▹
POST /api/register
Create new user account
-
▹
POST /api/login
Authenticate user and receive token
-
▹
POST /api/logout
Invalidate authentication token
-
▹
GET /api/profile
Retrieve authenticated user profile
Booking Management Endpoints (Protected)
-
▹
GET /api/bookings
List all bookings for authenticated user
-
▹
POST /api/bookings
Create new booking
-
▹
PUT /api/bookings/{id}
Update existing booking
-
▹
DELETE /api/bookings/{id}
Delete booking
Technical Highlights
Pricing Engine Architecture
The pricing system uses a sophisticated rule-based engine that evaluates multiple factors to calculate accurate booking costs.
- ▹ Prices stored in pence for precise calculations without floating-point errors
- ▹ Seasonal rates configurable for summer and winter periods
- ▹ Weekday/weekend rate variations for dynamic pricing
- ▹ Per-calendar-day evaluation for accurate multi-day bookings
Capacity Management
Intelligent capacity tracking ensures the car park never exceeds its maximum occupancy.
- ▹ Real-time availability checking before booking confirmation
- ▹ Per-day capacity evaluation for overlapping bookings
- ▹ Configurable capacity limits via application settings
Security & Authentication
Laravel Sanctum provides robust token-based authentication for secure API access.
- ▹ Stateless token authentication for scalability
- ▹ User-specific booking access and management
- ▹ Demo accounts seeded for testing (admin and customer roles)