A comprehensive web-based railway ticket booking system built with Laravel 12, featuring class-based pricing, real-time seat selection, automated booking management, and admin analytics.
- Features
- Tech Stack
- Installation
- Configuration
- Usage
- User Roles
- Key Features
- Project Structure
- API Endpoints
- Contributing
- License
- Advanced Search: Search trains by source, destination, journey date, train number, route, and departure time
- Real-time Availability: View live seat availability across all coach types
- Visual Seat Selection: Interactive seat map with color-coded availability
- Class-based Pricing: Dynamic pricing based on coach type:
- Sleeper: 1.0x base fare
- Second Class: 1.3x base fare
- First Class: 1.8x base fare
- AC Chair: 2.0x base fare
- AC First Class: 2.5x base fare
- Single Passenger Booking: Simplified booking with one passenger per reservation
- My Bookings Dashboard: View all bookings with status filtering
- Status Tracking: Real-time booking status (Pending, Confirmed, Cancelled, Completed)
- Booking Details: Comprehensive view of journey, passenger, and payment information
- Ticket Download: Generate and download PDF tickets for confirmed bookings
- Flexible Cancellation: Cancel bookings anytime before departure with time-based refunds:
- More than 48 hours: 90% refund
- 24-48 hours: 75% refund
- 12-24 hours: 50% refund
- 6-12 hours: 20% refund
- Less than 6 hours: 10% refund
- After departure: No cancellation allowed
- Multiple Payment Methods:
- bKash
- Nagad
- Rocket
- Credit/Debit Card
- Bank Transfer
- 5-Minute Payment Window: Countdown timer with automatic expiration
- Auto-Cancellation: Unpaid bookings automatically cancelled after 5 minutes
- Seat Release: Seats automatically released back to available pool
- Instant Confirmation: Immediate booking confirmation upon payment
- Profile Management: Update personal information (name, email, phone, address)
- Password Security: Change password with validation
- Account Status: View account status and membership details
- Booking History: Access complete booking history
- Real-time Statistics:
- Total Revenue (confirmed bookings)
- Active Bookings count
- Total Registered Users
- Available Trains
- Recent Bookings: Quick view of latest 10 bookings with details
- Visual Analytics: Overview of system activity
- CRUD Operations: Create, Read, Update, Delete trains
- Train Details:
- Train name and number
- Route (source and destination)
- Departure and arrival times
- Train type (Express, Mail, Local, Intercity)
- Facilities (AC, WiFi, Food, etc.)
- Base fare per seat
- Search & Filter: Filter trains by type, route, status
- Validation: Comprehensive input validation
- Complete Overview: View all bookings across the system
- Advanced Filters:
- Filter by booking status
- Filter by train
- Search by booking reference or passenger name
- Date range filtering
- Booking Actions:
- View detailed booking information
- Update booking status
- Cancel bookings with refund calculation
- View passenger details
- Track payment information
- Refund Processing: Automatic refund calculation based on cancellation time
- User CRUD: Complete user management system
- Role Assignment: Assign roles (Admin, Staff, Customer)
- User Search: Search by name, email, or role
- Account Status: Activate/deactivate user accounts
- User Details: View user profile and booking history
- Revenue Dashboard with Chart.js visualizations:
- Monthly Revenue Chart: Bar chart showing revenue trends
- Booking Status Distribution: Pie chart of booking statuses
- Popular Routes Chart: Horizontal bar chart of top routes
- Booking Statistics:
- Total bookings and confirmed bookings count
- Total and average revenue
- Cancellation rate
- Recent Bookings Table: Detailed list with passenger info
- Export Functionality: Generate reports for specific date ranges
- Popular Routes: Track and manage frequently booked routes
- Route Statistics: View booking counts per route
- Route Analysis: Identify profitable routes
- Application Settings: Configure system-wide settings
- Email Configuration: Set up email notifications
- Payment Gateway: Configure payment methods
- System Maintenance: Manage system maintenance mode
- Framework: Laravel 12.32.5
- PHP: 8.4.0
- Database: MySQL 8.0
- Authentication: Laravel Breeze
- Queue: Laravel Queue for background jobs
- CSS Frameworks:
- Tailwind CSS 3.4 (Customer interface)
- Bootstrap 5.3 (Admin panel)
- JavaScript: Alpine.js for interactive components
- Charts: Chart.js 4.4.0 for analytics
- Build Tool: Vite 5.x
- Adapter Pattern: Payment gateway integration
- Factory Pattern: Payment gateway factory
- Flyweight Pattern: Seat type optimization
- Proxy Pattern: Train availability caching
- PDF Generation: DomPDF for ticket generation
- Task Scheduling: Laravel Scheduler for automated tasks
- Validation: Comprehensive form validation
- Middleware: Custom authentication and authorization
- PHP >= 8.4.0
- Composer
- Node.js & NPM
- MySQL >= 8.0
git clone https://github.com/Torikul-048/Railway-Management-System.git
cd Railway-Management-Systemcomposer installnpm install# Copy environment file
copy .env.example .env
# Generate application key
php artisan key:generateEdit .env file with your database credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=railway_management
DB_USERNAME=root
DB_PASSWORD=your_passwordUpdate .env with your settings:
APP_NAME="Railway Management System"
APP_ENV=local
APP_DEBUG=true
APP_TIMEZONE=Asia/Dhaka
APP_URL=http://localhost:8000
# Email Configuration (Optional)
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@railway.com
MAIL_FROM_NAME="${APP_NAME}"# Run migrations
php artisan migrate
# Seed database with sample data
php artisan db:seedThis will create:
- 4 users (1 admin, 2 customers)
- 6 trains with different routes
- 20 train coaches (varied types)
- 950 seats across all coaches
- 3 sample bookings
npm run buildphp artisan serveThe scheduler automatically cancels unpaid bookings after 5 minutes.
Open a new terminal and run:
# Windows
start-scheduler.bat
# Or manually
php artisan schedule:work- Pending bookings won't auto-expire after 5 minutes
- Seats won't be released automatically
- Payment timer will show but won't enforce cancellation
Visit http://localhost:8000 in your browser.
After seeding, you'll have the following accounts:
Admin Account:
- Email:
admin@railway.com - Password:
password - Role: Admin
Customer Accounts:
-
Email:
customer@railway.com -
Password:
password -
Role: Customer
-
Email:
john@example.com -
Password:
password -
Role: Customer
Users Table:
- id, name, email, password
- phone, date_of_birth, gender
- national_id, address
- role (admin/staff/customer)
- timestamps
Trains Table:
- id, train_number, name
- source_station, destination_station
- departure_time, arrival_time
- route, train_type
- total_seats, available_seats
- fare_per_seat, facilities
- status (active/inactive)
- timestamps
Train Coaches Table:
- id, train_id, coach_number
- coach_type (sleeper/second_class/first_class/ac_chair/ac_first)
- total_seats, price_per_seat
- timestamps
Seats Table:
- id, train_coach_id, seat_number
- is_available, is_reserved
- reserved_until
- timestamps
Bookings Table:
- id, user_id, train_id, booking_reference
- booking_date, journey_date
- seat_numbers (JSON)
- passenger_details (JSON)
- total_fare
- booking_status (pending/confirmed/cancelled/completed)
- payment_status (pending/paid/refunded)
- payment_method, payment_reference
- refund_amount, refund_percentage
- cancelled_at, cancellation_reason
- timestamps
- Register/Login: Create account or login
- Search Trains: Enter journey details
- Select Train: Choose from available trains
- Select Seats: Pick seats from visual seat map
- Enter Details: Provide passenger information
- Make Payment: Choose payment method and complete within 5 minutes
- Download Ticket: Get PDF ticket after confirmation
- Manage Bookings: View, cancel, or download tickets
- Login: Access admin panel at
/admin/login - Dashboard: View system overview and statistics
- Manage Trains: Add, edit, or remove trains
- Manage Bookings: Monitor and manage all bookings
- User Management: Manage user accounts and roles
- View Reports: Analyze revenue and booking trends
- System Settings: Configure application settings
- Search and book train tickets
- View and manage own bookings
- Cancel bookings with refunds
- Update profile information
- Download tickets
- Full system access
- User management (CRUD)
- Train management (CRUD)
- Booking management (CRUD)
- Access to all reports and analytics
- System settings configuration
When a customer creates a booking:
- Status: Pending (seats reserved)
- Timer starts: 5:00 countdown
- Two outcomes:
- Paid within 5 minutes: Status β Confirmed β
- Not paid: Automatic cancellation, seats released β
The bookings:expire-pending command runs every minute via Laravel Scheduler to check and cancel expired bookings.
Each coach type has a multiplier on the train's base fare:
Sleeper: Base Fare Γ 1.0
Second Class: Base Fare Γ 1.3
First Class: Base Fare Γ 1.8
AC Chair: Base Fare Γ 2.0
AC First: Base Fare Γ 2.5Example: Train base fare = ΰ§³500
- Sleeper seat = ΰ§³500
- AC First seat = ΰ§³1,250
Refund percentage calculated based on time before departure:
if (hours_before >= 48) β 90% refund
else if (hours_before >= 24) β 75% refund
else if (hours_before >= 12) β 50% refund
else if (hours_before >= 6) β 20% refund
else if (hours_before > 0) β 10% refund
else β 0% (departed)The calculateRefundPercentage() method in Booking model handles this logic.
Interactive seat map with:
- β Green = Available
- π΄ Red = Booked
- π‘ Yellow = Selected (by user)
- Real-time price calculation
- Coach type identification
- Seat number display
Laravel Scheduler runs bookings:expire-pending every minute:
- Finds bookings with status=pending and payment_status=pending
- Checks if booking_date <= 5 minutes ago
- Updates booking status to cancelled
- Releases all reserved seats
- Logs cancellation reason
- Timezone: Asia/Dhaka (UTC+6)
- Date pickers show Bangladesh dates
- Journey date validation uses BD time
- All timestamps in BD timezone
Railway-Management-System/
βββ app/
β βββ Adapters/ # Payment adapter pattern
β βββ Console/Commands/ # Artisan commands
β β βββ ExpirePendingBookings.php
β βββ Factories/ # Factory pattern
β βββ Flyweights/ # Flyweight pattern
β βββ Http/
β β βββ Controllers/
β β β βββ Admin/ # Admin controllers
β β β βββ Auth/ # Authentication
β β β βββ BookingController.php
β β β βββ ProfileController.php
β β β βββ TrainSearchController.php
β β βββ Middleware/
β β βββ RedirectIfAdmin.php
β βββ Models/
β β βββ Booking.php # Booking model with refund logic
β β βββ Seat.php
β β βββ Train.php
β β βββ TrainCoach.php
β β βββ User.php
β βββ Proxies/ # Proxy pattern
βββ database/
β βββ migrations/ # Database migrations
β βββ seeders/ # Database seeders
βββ public/ # Public assets
βββ resources/
β βββ css/
β β βββ app.css # Tailwind CSS
β βββ js/
β β βββ app.js # Main JavaScript
β β βββ bootstrap.js # Bootstrap setup
β βββ views/
β βββ admin/ # Admin panel views
β βββ auth/ # Authentication views
β βββ bookings/ # Booking views
β βββ layouts/ # Layout templates
β βββ profile/ # Profile views
β βββ trains/ # Train search views
βββ routes/
β βββ console.php # Scheduler configuration
β βββ web.php # Web routes
βββ storage/ # File storage
βββ tests/ # Unit & feature tests
βββ .env.example # Environment template
βββ composer.json # PHP dependencies
βββ package.json # Node dependencies
βββ README.md # This file
βββ start-scheduler.bat # Scheduler startup script
βββ vite.config.js # Vite configuration
GET /- Home pageGET /login- Login pagePOST /login- Login actionGET /register- Registration pagePOST /register- Registration action
GET /trains/search- Search trainsGET /trains/{train}/details- Train detailsGET /trains/{train}/select-seats- Seat selectionPOST /bookings/reserve-seats- Reserve seatsPOST /trains/{train}/book- Create bookingGET /bookings/{booking}/payment- Payment pagePOST /bookings/{booking}/process-payment- Process paymentGET /bookings/{booking}/confirmation- Booking confirmationGET /my-bookings- View bookingsGET /bookings/{booking}/download-ticket- Download ticketGET /bookings/{booking}/cancel- Cancel booking formPOST /bookings/{booking}/cancel- Cancel booking actionGET /profile- User profilePATCH /profile- Update profileDELETE /profile- Delete account
GET /admin/dashboard- Admin dashboardGET /admin/users- User managementPOST /admin/users- Create userGET /admin/users/{user}- View userPUT /admin/users/{user}- Update userDELETE /admin/users/{user}- Delete userGET /admin/trains- Train managementPOST /admin/trains- Create trainGET /admin/trains/{train}- View trainPUT /admin/trains/{train}- Update trainDELETE /admin/trains/{train}- Delete trainGET /admin/bookings- Booking managementGET /admin/bookings/{booking}- View bookingPUT /admin/bookings/{booking}- Update bookingPOST /admin/bookings/{booking}/cancel- Cancel bookingGET /admin/reports- Reports & analyticsGET /admin/routes- Route managementGET /admin/settings- System settings
- β CSRF protection on all forms
- β SQL injection prevention (Eloquent ORM)
- β XSS protection (Blade templating)
- β Password hashing (bcrypt)
- β Role-based access control
- β Middleware authentication
- β Input validation
- β Session management
- β Environment variable protection
- β HTTPS ready (production)
Run tests:
# Run all tests
php artisan test
# Run specific test
php artisan test --filter BookingTest
# Run with coverage
php artisan test --coverageThe system uses Laravel Scheduler for automated tasks:
Expire Pending Bookings:
php artisan bookings:expire-pending- Runs every minute via scheduler
- Cancels bookings older than 5 minutes
- Releases reserved seats
- Updates booking status
To run scheduler manually:
php artisan schedule:work- Set
APP_ENV=productionin.env - Set
APP_DEBUG=falsein.env - Configure proper database credentials
- Set up SSL certificate (HTTPS)
- Configure email service
- Set up cron job for scheduler:
* * * * * cd /path-to-project && php artisan schedule:run >> /dev/null 2>&1
- Optimize application:
php artisan config:cache php artisan route:cache php artisan view:cache php artisan optimize
- Set proper file permissions
- Configure backup strategy
- Set up monitoring and logging
This project is open-source and available under the MIT License.
Torikul Islam
- GitHub: @Torikul-048
- Email: torikulislam732978@gmail.com
Farid Patwary
- GitHub: @Farid-43
- Email: faridpatwary2020@gmail.com
Sayeem
- GitHub: @Sayeem33
- Email: Sayeem2107033@stud.kuet.ac.bd
- Laravel Framework
- Tailwind CSS
- Bootstrap
- Chart.js
- Alpine.js
- All open-source contributors
For support, email torikulislam732978@gmail.com, faridpatwary2020@gmail.com, Sayeem2107033@stud.kuet.ac.bd or open an issue on GitHub.