Skip to content

Commit 8dde8d7

Browse files
committed
basic structure based off rails example
1 parent 1186953 commit 8dde8d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+12040
-0
lines changed

frameworks-laravel/.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2
16+
17+
[compose.yaml]
18+
indent_size = 4

frameworks-laravel/.env.example

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
APP_NAME=Laravel
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
APP_LOCALE=en
8+
APP_FALLBACK_LOCALE=en
9+
APP_FAKER_LOCALE=en_US
10+
11+
APP_MAINTENANCE_DRIVER=file
12+
# APP_MAINTENANCE_STORE=database
13+
14+
# PHP_CLI_SERVER_WORKERS=4
15+
16+
BCRYPT_ROUNDS=12
17+
18+
LOG_CHANNEL=stack
19+
LOG_STACK=single
20+
LOG_DEPRECATIONS_CHANNEL=null
21+
LOG_LEVEL=debug
22+
23+
DB_CONNECTION=sqlite
24+
# DB_HOST=127.0.0.1
25+
# DB_PORT=3306
26+
# DB_DATABASE=laravel
27+
# DB_USERNAME=root
28+
# DB_PASSWORD=
29+
30+
SESSION_DRIVER=database
31+
SESSION_LIFETIME=120
32+
SESSION_ENCRYPT=false
33+
SESSION_PATH=/
34+
SESSION_DOMAIN=null
35+
36+
BROADCAST_CONNECTION=log
37+
FILESYSTEM_DISK=local
38+
QUEUE_CONNECTION=database
39+
40+
CACHE_STORE=database
41+
# CACHE_PREFIX=
42+
43+
MEMCACHED_HOST=127.0.0.1
44+
45+
REDIS_CLIENT=phpredis
46+
REDIS_HOST=127.0.0.1
47+
REDIS_PASSWORD=null
48+
REDIS_PORT=6379
49+
50+
MAIL_MAILER=log
51+
MAIL_SCHEME=null
52+
MAIL_HOST=127.0.0.1
53+
MAIL_PORT=2525
54+
MAIL_USERNAME=null
55+
MAIL_PASSWORD=null
56+
MAIL_FROM_ADDRESS="[email protected]"
57+
MAIL_FROM_NAME="${APP_NAME}"
58+
59+
AWS_ACCESS_KEY_ID=
60+
AWS_SECRET_ACCESS_KEY=
61+
AWS_DEFAULT_REGION=us-east-1
62+
AWS_BUCKET=
63+
AWS_USE_PATH_STYLE_ENDPOINT=false
64+
65+
VITE_APP_NAME="${APP_NAME}"

frameworks-laravel/.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* text=auto eol=lf
2+
3+
*.blade.php diff=html
4+
*.css diff=css
5+
*.html diff=html
6+
*.md diff=markdown
7+
*.php diff=php
8+
9+
/.github export-ignore
10+
CHANGELOG.md export-ignore
11+
.styleci.yml export-ignore

frameworks-laravel/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
*.log
2+
.DS_Store
3+
.env
4+
.env.backup
5+
.env.production
6+
.phpactor.json
7+
.phpunit.result.cache
8+
/.fleet
9+
/.idea
10+
/.nova
11+
/.phpunit.cache
12+
/.vscode
13+
/.zed
14+
/auth.json
15+
/node_modules
16+
/public/build
17+
/public/hot
18+
/public/storage
19+
/storage/*.key
20+
/storage/pail
21+
/vendor
22+
Homestead.json
23+
Homestead.yaml
24+
Thumbs.db

frameworks-laravel/README.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# F1 Laps API - Laravel PHP
2+
3+
A Laravel PHP implementation of the Formula 1 lap times API. This API provides endpoints for managing drivers, circuits, and lap time data.
4+
5+
## Overview
6+
7+
This is a Laravel version of the F1 Laps API, providing the same functionality as the Rails version but built with PHP and Laravel framework.
8+
9+
## Features
10+
11+
- **Drivers Management**: Create and list F1 drivers
12+
- **Circuits Management**: Create and list racing circuits
13+
- **Lap Times**: Record and query lap times with flexible filtering
14+
- **Health Check**: API health and version information
15+
16+
## Setup
17+
18+
### Prerequisites
19+
20+
- PHP 8.2 or higher
21+
- Composer
22+
- SQLite (default) or MySQL/PostgreSQL
23+
24+
### Installation
25+
26+
1. Install dependencies:
27+
```bash
28+
composer install
29+
```
30+
31+
2. Set up your environment:
32+
```bash
33+
cp .env.example .env
34+
php artisan key:generate
35+
```
36+
37+
3. Run migrations and seed the database with demo data:
38+
```bash
39+
php artisan migrate --seed
40+
```
41+
42+
Or to start fresh with demo data:
43+
```bash
44+
php artisan migrate:fresh --seed
45+
```
46+
47+
4. Start the development server:
48+
```bash
49+
php artisan serve
50+
```
51+
52+
The API will be available at `http://localhost:8000`.
53+
54+
## Demo Data
55+
56+
The application includes database seeders that populate the database with realistic F1 data:
57+
- **10 F1 Drivers** (Verstappen, Hamilton, Leclerc, Norris, etc.)
58+
- **10 Famous Circuits** (Monaco, Silverstone, Monza, Spa, etc.)
59+
- **30+ Lap Times** with realistic lap times in milliseconds
60+
61+
This demo data makes it easy to test the API endpoints without having to create data manually.
62+
63+
## API Endpoints
64+
65+
All endpoints are prefixed with `/api/v1`.
66+
67+
### Health Check
68+
69+
- `GET /api/v1/health` - Get API health status
70+
71+
### Drivers
72+
73+
- `GET /api/v1/drivers` - List all drivers
74+
- `POST /api/v1/drivers` - Create a new driver
75+
76+
**Create Driver Request:**
77+
```json
78+
{
79+
"name": "Lewis Hamilton",
80+
"code": "HAM"
81+
}
82+
```
83+
84+
### Circuits
85+
86+
- `GET /api/v1/circuits` - List all circuits
87+
- `POST /api/v1/circuits` - Create a new circuit
88+
89+
**Create Circuit Request:**
90+
```json
91+
{
92+
"name": "Monaco Grand Prix",
93+
"location": "Monte Carlo, Monaco"
94+
}
95+
```
96+
97+
### Lap Times
98+
99+
- `GET /api/v1/lap_times` - List all lap times (with optional filters)
100+
- Query parameters:
101+
- `driver_id` - Filter by driver ID
102+
- `circuit_id` - Filter by circuit ID
103+
- `lap_min` - Minimum lap number
104+
- `lap_max` - Maximum lap number
105+
- `POST /api/v1/lap_times` - Create a new lap time
106+
- `GET /api/v1/drivers/{driverId}/lap_times` - Get lap times for a specific driver
107+
- `GET /api/v1/circuits/{circuitId}/lap_times` - Get lap times for a specific circuit
108+
109+
**Create Lap Time Request:**
110+
```json
111+
{
112+
"driver_id": 1,
113+
"circuit_id": 1,
114+
"lap_number": 1,
115+
"time_ms": 82345
116+
}
117+
```
118+
119+
## Testing
120+
121+
Run the tests:
122+
```bash
123+
php artisan test
124+
```
125+
126+
## OpenAPI Specification
127+
128+
The OpenAPI specification is available in `openapi.yaml`. This spec is compatible with the Rails version and can be used to generate SDKs using Speakeasy.
129+
130+
## Database
131+
132+
By default, the application uses SQLite. The database file is created at `database/database.sqlite`.
133+
134+
To use a different database, update your `.env` file accordingly.
135+
136+
## Models
137+
138+
### Driver
139+
- `id`: Integer (auto-increment)
140+
- `name`: String
141+
- `code`: String (indexed)
142+
- `created_at`: Timestamp
143+
- `updated_at`: Timestamp
144+
145+
### Circuit
146+
- `id`: Integer (auto-increment)
147+
- `name`: String
148+
- `location`: String
149+
- `created_at`: Timestamp
150+
- `updated_at`: Timestamp
151+
152+
### LapTime
153+
- `id`: Integer (auto-increment)
154+
- `driver_id`: Integer (foreign key to drivers)
155+
- `circuit_id`: Integer (foreign key to circuits)
156+
- `lap_number`: Integer
157+
- `time_ms`: Integer (lap time in milliseconds)
158+
- `created_at`: Timestamp
159+
- `updated_at`: Timestamp
160+
161+
## Development
162+
163+
### Running Locally
164+
165+
```bash
166+
php artisan serve
167+
```
168+
169+
The API will be available at `http://localhost:8000`.
170+
171+
### Artisan Commands
172+
173+
Laravel provides various artisan commands for development:
174+
175+
```bash
176+
# Run migrations
177+
php artisan migrate
178+
179+
# Rollback migrations
180+
php artisan migrate:rollback
181+
182+
# Create a new migration
183+
php artisan make:migration create_table_name
184+
185+
# Create a new model
186+
php artisan make:model ModelName
187+
188+
# Create a new controller
189+
php artisan make:controller ControllerName
190+
```
191+
192+
## License
193+
194+
This project is licensed under the MIT License.
195+
196+
197+
198+
## Code of Conduct
199+
200+
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
201+
202+
## Security Vulnerabilities
203+
204+
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [[email protected]](mailto:[email protected]). All security vulnerabilities will be promptly addressed.
205+
206+
## License
207+
208+
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api\V1;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Circuit;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Http\JsonResponse;
9+
10+
class CircuitController extends Controller
11+
{
12+
/**
13+
* Display a listing of the resource.
14+
*/
15+
public function index(): JsonResponse
16+
{
17+
return response()->json(Circuit::all());
18+
}
19+
20+
/**
21+
* Store a newly created resource in storage.
22+
*/
23+
public function store(Request $request): JsonResponse
24+
{
25+
$validated = $request->validate([
26+
'name' => 'required|string',
27+
'location' => 'required|string',
28+
]);
29+
30+
$circuit = Circuit::create($validated);
31+
32+
return response()->json($circuit, 201);
33+
}
34+
35+
/**
36+
* Display the specified resource.
37+
*/
38+
public function show(string $id)
39+
{
40+
//
41+
}
42+
43+
/**
44+
* Update the specified resource in storage.
45+
*/
46+
public function update(Request $request, string $id)
47+
{
48+
//
49+
}
50+
51+
/**
52+
* Remove the specified resource from storage.
53+
*/
54+
public function destroy(string $id)
55+
{
56+
//
57+
}
58+
}

0 commit comments

Comments
 (0)