A simple RESTful API built with Laravel 9 using JSON Web Tokens (JWT) for Event -Booking.
- User registration
- User login with JWT
- Token-based authentication
- Secure route access using middleware
- Laravel 9 and Tymon JWTAuth integration
- PHP >= 8.0
- Composer
- Laravel 9
- MySQL or any supported DB
- WAMP/XAMPP/Laragon (or your preferred local server)
- Clone the repository:
git clone https://github.com/yourusername/event-booking
cd event-booking- Install dependencies:
composer install- Copy
.envfile:
cp .env.example .env- Generate application key:
php artisan key:generate- Configure your database in
.env:
DB_DATABASE=your_db
DB_USERNAME=root
DB_PASSWORD=- Run migrations:
php artisan migrate- Install JWT package:
composer require tymon/jwt-auth- Publish JWT config:
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"- Generate JWT secret:
php artisan jwt:secret- Serve the app:
php artisan serve| Method | Endpoint | Description |
|---|---|---|
| POST | /api/register |
Register a new user |
| POST | /api/login |
Login and get token |
| GET | /api/user |
Get authenticated user (requires token) |
Add auth:api middleware to protect routes:
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});app/Http/Controllers/API/AuthController.php
config/auth.php
routes/api.php
This project is open-sourced software licensed under the MIT license.