base-api-scramble-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -0
- package/docs/AI-GUIDE-COMPLETE.md +372 -0
- package/docs/EXCEL-EXPORT-SERVICE.md +349 -0
- package/docs/EXPORT-DATA-PROVIDERS.md +340 -0
- package/docs/EXPORT-TEMPLATES.md +459 -0
- package/docs/LARAVEL-API-TEST.md +355 -0
- package/docs/MAKE-EXPORT-EXCEL-COMMAND.md +215 -0
- package/docs/README.md +678 -0
- package/docs/STRUCTURE.md +540 -0
- package/docs/starting_point.md +423 -0
- package/index.js +968 -0
- package/package.json +17 -0
package/docs/README.md
ADDED
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
# ๐ Laravel API Base with Query Pattern v6.0
|
|
2
|
+
|
|
3
|
+
[](https://laravel.com)
|
|
4
|
+
[](https://php.net)
|
|
5
|
+
[](https://laravel.com/docs/sanctum)
|
|
6
|
+
[](https://scramble.dedoc.co)
|
|
7
|
+
|
|
8
|
+
> **Production-ready Laravel API with Query Pattern, Spatie QueryBuilder, and Auto-generated OpenAPI Documentation**
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## ๐ฏ Architecture
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
Request โ Controller โ Query Class โ Model โ Response
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**What makes this different?**
|
|
19
|
+
- โ
**Query Classes** for business logic separation
|
|
20
|
+
- โ
**Spatie QueryBuilder** for advanced filtering
|
|
21
|
+
- โ
**Queryable Trait** for consistent API behavior
|
|
22
|
+
- โ
**Scramble Pro** for auto-generated API docs
|
|
23
|
+
- โ
**Activity Logging** for audit trails
|
|
24
|
+
- โ
**FileService** with auto-compression
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## โก TWO POWERFUL WORKFLOWS
|
|
29
|
+
|
|
30
|
+
### Workflow A: Fields-First (Quick & Simple)
|
|
31
|
+
```bash
|
|
32
|
+
php artisan gc Product --fields=name,price:decimal,image:file
|
|
33
|
+
php artisan migrate
|
|
34
|
+
```
|
|
35
|
+
**Perfect for:** Simple schemas, clear requirements
|
|
36
|
+
|
|
37
|
+
### Workflow B: Migration-First (Recommended)
|
|
38
|
+
```bash
|
|
39
|
+
# 1. Create/Generate migration
|
|
40
|
+
# 2. Generate complete CRUD from migration
|
|
41
|
+
php artisan gc:from-migration products
|
|
42
|
+
php artisan migrate
|
|
43
|
+
```
|
|
44
|
+
**Perfect for:** Complex schemas, AI-generated migrations, existing projects
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## ๐ฏ Migration-First Example
|
|
49
|
+
|
|
50
|
+
**Step 1:** Create migration (manually or AI-generated)
|
|
51
|
+
```php
|
|
52
|
+
// database/migrations/2024_xx_xx_create_products_table.php
|
|
53
|
+
Schema::create('products', function (Blueprint $table) {
|
|
54
|
+
$table->uuid('id')->primary();
|
|
55
|
+
$table->string('name');
|
|
56
|
+
$table->text('description');
|
|
57
|
+
$table->decimal('price', 10, 2);
|
|
58
|
+
$table->integer('stock');
|
|
59
|
+
$table->string('image')->nullable();
|
|
60
|
+
$table->foreignUuid('category_id')->constrained()->cascadeOnDelete();
|
|
61
|
+
$table->timestamps();
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Step 2:** Generate complete CRUD
|
|
66
|
+
```bash
|
|
67
|
+
php artisan gc:from-migration products
|
|
68
|
+
php artisan migrate
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Result:** Complete production-ready API! ๐
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
โ
Generated Files:
|
|
75
|
+
โโโ app/Models/Product.php (with Queryable trait)
|
|
76
|
+
โโโ app/Queries/ProductQuery.php (filtering logic)
|
|
77
|
+
โโโ app/Http/Controllers/Api/V1/ProductController.php
|
|
78
|
+
โโโ app/Http/Requests/Api/V1/ProductStoreRequest.php
|
|
79
|
+
โโโ app/Http/Requests/Api/V1/ProductUpdateRequest.php
|
|
80
|
+
โโโ routes/api_v1.php (auto-registered)
|
|
81
|
+
|
|
82
|
+
โ
Auto-detected:
|
|
83
|
+
โโโ Fields & Types
|
|
84
|
+
โโโ Foreign keys โ belongsTo relationships
|
|
85
|
+
โโโ File upload โ FileService integration
|
|
86
|
+
โโโ Searchable columns
|
|
87
|
+
|
|
88
|
+
โ
API Endpoints:
|
|
89
|
+
โโโ GET /api/v1/products
|
|
90
|
+
โโโ GET /api/v1/products/{id}
|
|
91
|
+
โโโ POST /api/v1/products
|
|
92
|
+
โโโ PUT /api/v1/products/{id}
|
|
93
|
+
โโโ DELETE /api/v1/products/{id}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## ๐ฆ What Gets Generated
|
|
99
|
+
|
|
100
|
+
### Standard Generation (6 Files + Routes)
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
app/
|
|
104
|
+
โโโ Models/Product.php # Model + Queryable trait
|
|
105
|
+
โ โโโ $fillable (all columns)
|
|
106
|
+
โ โโโ $searchable (text columns)
|
|
107
|
+
โ โโโ $relationIncludes (detected relations)
|
|
108
|
+
โ โโโ relationships (belongsTo, hasMany)
|
|
109
|
+
โ โโโ accessors (image_url, etc)
|
|
110
|
+
โ
|
|
111
|
+
โโโ Queries/ProductQuery.php # Business Logic Layer
|
|
112
|
+
โ โโโ extends Spatie QueryBuilder
|
|
113
|
+
โ โโโ allowedIncludes (relations)
|
|
114
|
+
โ โโโ allowedFilters (all columns)
|
|
115
|
+
โ
|
|
116
|
+
โโโ Http/
|
|
117
|
+
โ โโโ Controllers/Api/V1/
|
|
118
|
+
โ โ โโโ ProductController.php # Clean CRUD Logic
|
|
119
|
+
โ โ โโโ index() with Query class
|
|
120
|
+
โ โ โโโ show()
|
|
121
|
+
โ โ โโโ store() with FileService
|
|
122
|
+
โ โ โโโ update() with FileService
|
|
123
|
+
โ โ โโโ destroy() with file cleanup
|
|
124
|
+
โ โ
|
|
125
|
+
โ โโโ Requests/Api/V1/
|
|
126
|
+
โ โโโ ProductStoreRequest.php # Create Validation
|
|
127
|
+
โ โ โโโ PHPDoc for Scramble
|
|
128
|
+
โ โ โโโ comprehensive rules
|
|
129
|
+
โ โ
|
|
130
|
+
โ โโโ ProductUpdateRequest.php # Update Validation
|
|
131
|
+
โ โโโ 'sometimes' rules
|
|
132
|
+
โ โโโ nullable handling
|
|
133
|
+
โ
|
|
134
|
+
routes/api_v1.php
|
|
135
|
+
โโโ Route::apiResource('products', ProductController::class);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## ๐ Built-in Query Features (Via Queryable Trait)
|
|
141
|
+
|
|
142
|
+
### Filtering
|
|
143
|
+
```bash
|
|
144
|
+
GET /api/v1/products?filter[name]=iPhone
|
|
145
|
+
GET /api/v1/products?filter[category_id]=uuid
|
|
146
|
+
GET /api/v1/products?filter[price]=1000000
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Global Search
|
|
150
|
+
```bash
|
|
151
|
+
GET /api/v1/products?search=iPhone
|
|
152
|
+
# Searches across all $searchable columns
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Sorting
|
|
156
|
+
```bash
|
|
157
|
+
GET /api/v1/products?sort=name # Ascending
|
|
158
|
+
GET /api/v1/products?sort=-price # Descending
|
|
159
|
+
GET /api/v1/products?sort=price,-stock # Multiple
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Pagination
|
|
163
|
+
```bash
|
|
164
|
+
GET /api/v1/products?paginate=20
|
|
165
|
+
GET /api/v1/products?paginate=20&page=2
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Including Relations
|
|
169
|
+
```bash
|
|
170
|
+
GET /api/v1/products?include=category
|
|
171
|
+
GET /api/v1/products?include=category,brand,reviews
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Field Selection
|
|
175
|
+
```bash
|
|
176
|
+
GET /api/v1/products?fields[products]=id,name,price
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Combined (Real-world Example)
|
|
180
|
+
```bash
|
|
181
|
+
GET /api/v1/products?search=iPhone&filter[category_id]=uuid&sort=-price&include=category&paginate=15
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## ๐จ API Response Format
|
|
187
|
+
|
|
188
|
+
### Success Response
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"success": true,
|
|
192
|
+
"code": 200,
|
|
193
|
+
"message": "Product retrieved successfully",
|
|
194
|
+
"data": {
|
|
195
|
+
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
196
|
+
"name": "iPhone 14 Pro",
|
|
197
|
+
"price": 15000000,
|
|
198
|
+
"image": "product_1234567890.jpg",
|
|
199
|
+
"image_url": "https://api.test/uploads/products/product_1234567890.jpg",
|
|
200
|
+
"category": {
|
|
201
|
+
"id": "...",
|
|
202
|
+
"name": "Smartphones"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Paginated Response
|
|
209
|
+
```json
|
|
210
|
+
{
|
|
211
|
+
"success": true,
|
|
212
|
+
"code": 200,
|
|
213
|
+
"message": "Products retrieved successfully",
|
|
214
|
+
"data": [...],
|
|
215
|
+
"pagination": {
|
|
216
|
+
"current_page": 1,
|
|
217
|
+
"from": 1,
|
|
218
|
+
"to": 10,
|
|
219
|
+
"total": 50,
|
|
220
|
+
"per_page": 10,
|
|
221
|
+
"last_page": 5,
|
|
222
|
+
"next_page": 2,
|
|
223
|
+
"prev_page": null,
|
|
224
|
+
"path": "https://api.test/api/v1/products"
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Error Response
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"success": false,
|
|
233
|
+
"code": 422,
|
|
234
|
+
"message": "Validation failed",
|
|
235
|
+
"errors": {
|
|
236
|
+
"name": ["The name field is required."]
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## ๐ง Available Commands
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Standard generation (Fields-First)
|
|
247
|
+
php artisan gc Product --fields=name,price:decimal,image:file
|
|
248
|
+
|
|
249
|
+
# From migration (Migration-First) โญ RECOMMENDED
|
|
250
|
+
php artisan gc:from-migration products
|
|
251
|
+
|
|
252
|
+
# With relationships
|
|
253
|
+
php artisan gc Product --belongsTo=Category,Brand --hasMany=Review
|
|
254
|
+
|
|
255
|
+
# Interactive wizard
|
|
256
|
+
php artisan gc:wizard Product
|
|
257
|
+
|
|
258
|
+
# Preview only (no file creation)
|
|
259
|
+
php artisan gc Product --fields=name,price --preview
|
|
260
|
+
|
|
261
|
+
# Migration text only
|
|
262
|
+
php artisan gc Product --fields=name,price --migration
|
|
263
|
+
|
|
264
|
+
# Show help
|
|
265
|
+
php artisan gc:help
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## ๐ Field Types Reference
|
|
271
|
+
|
|
272
|
+
| Type | Example | Database | Notes |
|
|
273
|
+
|------|---------|----------|-------|
|
|
274
|
+
| `string` | `name:string` | VARCHAR(255) | Default type |
|
|
275
|
+
| `text` | `description:text` | TEXT | Long text |
|
|
276
|
+
| `decimal` | `price:decimal` | DECIMAL(10,2) | For money |
|
|
277
|
+
| `integer` | `stock:integer` | INTEGER | Whole numbers |
|
|
278
|
+
| `boolean` | `is_active:boolean` | BOOLEAN | true/false |
|
|
279
|
+
| `datetime` | `published_at:datetime` | DATETIME | With time |
|
|
280
|
+
| `date` | `birth_date:date` | DATE | Date only |
|
|
281
|
+
| `file` | `image:file` | VARCHAR(255) | โญ Auto FileService |
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## ๐จ File Upload Features
|
|
286
|
+
|
|
287
|
+
**Automatic when `image:file` or similar detected:**
|
|
288
|
+
|
|
289
|
+
```php
|
|
290
|
+
// Auto-generated in Controller
|
|
291
|
+
$file = $this->fileService->saveFileComplete(
|
|
292
|
+
file: $request->file('image'),
|
|
293
|
+
folder: 'products', // organized folders
|
|
294
|
+
fileName: 'product_' . time(), // custom naming
|
|
295
|
+
is_compressed: true, // auto-compression for images
|
|
296
|
+
);
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**Features:**
|
|
300
|
+
- โ
Auto-compression for images (jpg, png)
|
|
301
|
+
- โ
Organized folder structure
|
|
302
|
+
- โ
Safe file deletion on update/delete
|
|
303
|
+
- โ
URL accessor (image_url) auto-generated
|
|
304
|
+
- โ
Validation rules auto-added
|
|
305
|
+
|
|
306
|
+
**File storage:**
|
|
307
|
+
```
|
|
308
|
+
storage/app/public/
|
|
309
|
+
โโโ products/
|
|
310
|
+
โโโ product_1234567890.jpg
|
|
311
|
+
โโโ product_1234567891.jpg
|
|
312
|
+
โโโ ...
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## ๐ Quick Start
|
|
318
|
+
|
|
319
|
+
### 1. Install Dependencies
|
|
320
|
+
```bash
|
|
321
|
+
composer install
|
|
322
|
+
cp .env.example .env
|
|
323
|
+
php artisan key:generate
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### 2. Configure Database
|
|
327
|
+
```env
|
|
328
|
+
DB_CONNECTION=mysql
|
|
329
|
+
DB_HOST=127.0.0.1
|
|
330
|
+
DB_PORT=3306
|
|
331
|
+
DB_DATABASE=your_database
|
|
332
|
+
DB_USERNAME=your_username
|
|
333
|
+
DB_PASSWORD=your_password
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### 3. Run Migrations
|
|
337
|
+
```bash
|
|
338
|
+
php artisan migrate
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### 4. Create Storage Link
|
|
342
|
+
```bash
|
|
343
|
+
php artisan storage:link
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### 5. Generate Your First CRUD
|
|
347
|
+
```bash
|
|
348
|
+
# Option A: Fields-First
|
|
349
|
+
php artisan gc Product --fields=name,price:decimal,image:file
|
|
350
|
+
php artisan migrate
|
|
351
|
+
|
|
352
|
+
# Option B: Migration-First (Recommended)
|
|
353
|
+
# 1. Create migration file
|
|
354
|
+
# 2. Run:
|
|
355
|
+
php artisan gc:from-migration products
|
|
356
|
+
php artisan migrate
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### 6. Test API
|
|
360
|
+
```bash
|
|
361
|
+
# Start server
|
|
362
|
+
php artisan serve
|
|
363
|
+
|
|
364
|
+
# Test endpoint
|
|
365
|
+
curl http://localhost:8000/api/v1/products
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## ๐ Authentication
|
|
371
|
+
|
|
372
|
+
All API routes protected with Laravel Sanctum.
|
|
373
|
+
|
|
374
|
+
### Login
|
|
375
|
+
```bash
|
|
376
|
+
POST /api/v1/login
|
|
377
|
+
Content-Type: application/json
|
|
378
|
+
|
|
379
|
+
{
|
|
380
|
+
"email": "user@example.com",
|
|
381
|
+
"password": "password"
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Use Token
|
|
386
|
+
```bash
|
|
387
|
+
GET /api/v1/products
|
|
388
|
+
Authorization: Bearer {your-token-here}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## ๐ Tech Stack
|
|
394
|
+
|
|
395
|
+
| Component | Package | Version | Purpose |
|
|
396
|
+
|-----------|---------|---------|---------|
|
|
397
|
+
| Framework | Laravel | ^10.10 | Core framework |
|
|
398
|
+
| PHP | - | ^8.1 | Language |
|
|
399
|
+
| Auth | Laravel Sanctum | ^3.3 | API authentication |
|
|
400
|
+
| Permissions | Spatie Permission | ^6.13 | RBAC |
|
|
401
|
+
| Query Builder | Spatie Query Builder | ^6.3 | Advanced filtering |
|
|
402
|
+
| Activity Log | Spatie Activity Log | ^4.9 | Audit trail |
|
|
403
|
+
| API Docs | Scramble + Pro | ^0.12.35 / ^0.7.18 | OpenAPI docs |
|
|
404
|
+
| Testing | PHPUnit | ^10.1 | Unit testing |
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
## ๐ Documentation
|
|
409
|
+
|
|
410
|
+
- **[STRUCTURE.md](STRUCTURE.md)** - Complete project structure
|
|
411
|
+
- **[AI-GUIDE-COMPLETE.md](docs/AI-GUIDE-COMPLETE.md)** - Comprehensive AI integration guide
|
|
412
|
+
- **[DESCRIPTION.md](DESCRIPTION.md)** - Project description (if exists)
|
|
413
|
+
|
|
414
|
+
### API Documentation
|
|
415
|
+
Access auto-generated Scramble documentation:
|
|
416
|
+
```
|
|
417
|
+
http://your-app.test/docs/api
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## ๐ฏ Key Features
|
|
423
|
+
|
|
424
|
+
### ๐๏ธ Query Builder Pattern
|
|
425
|
+
- Dedicated Query classes for business logic
|
|
426
|
+
- Clean separation from controllers
|
|
427
|
+
- Reusable across endpoints
|
|
428
|
+
- Easy to test and maintain
|
|
429
|
+
|
|
430
|
+
### ๐ Advanced Filtering (Spatie QueryBuilder)
|
|
431
|
+
- Filter by any column
|
|
432
|
+
- Global search across multiple columns
|
|
433
|
+
- Sort by multiple fields
|
|
434
|
+
- Include nested relations
|
|
435
|
+
- Field selection for optimization
|
|
436
|
+
|
|
437
|
+
### ๐ Queryable Trait
|
|
438
|
+
- Consistent behavior across all models
|
|
439
|
+
- Auto-generates allowed filters
|
|
440
|
+
- Global search functionality
|
|
441
|
+
- Relationship includes
|
|
442
|
+
- Zero repetitive code
|
|
443
|
+
|
|
444
|
+
### ๐จ Standardized Responses (ApiResponse Helper)
|
|
445
|
+
- Consistent JSON structure
|
|
446
|
+
- Auto-detect pagination
|
|
447
|
+
- Clean error handling
|
|
448
|
+
- Success/Error/Created/Deleted methods
|
|
449
|
+
|
|
450
|
+
### ๐ธ FileService
|
|
451
|
+
- Centralized file handling
|
|
452
|
+
- Auto-compression for images
|
|
453
|
+
- Safe deletion
|
|
454
|
+
- Organized storage structure
|
|
455
|
+
- URL accessors
|
|
456
|
+
|
|
457
|
+
### ๐ Scramble Pro Integration
|
|
458
|
+
- Auto-generated OpenAPI documentation
|
|
459
|
+
- Always up-to-date
|
|
460
|
+
- Interactive API testing
|
|
461
|
+
- PHPDoc-based annotations
|
|
462
|
+
|
|
463
|
+
### ๐ Activity Logging
|
|
464
|
+
- Automatic audit trail
|
|
465
|
+
- Model observers
|
|
466
|
+
- Track all changes
|
|
467
|
+
- User attribution
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
## ๐ Best Practices Implemented
|
|
472
|
+
|
|
473
|
+
1. **Separation of Concerns**
|
|
474
|
+
- Controllers handle routing
|
|
475
|
+
- Query classes handle business logic
|
|
476
|
+
- Models handle data access
|
|
477
|
+
- Services handle specific operations
|
|
478
|
+
|
|
479
|
+
2. **DRY Principle**
|
|
480
|
+
- Queryable trait for shared functionality
|
|
481
|
+
- ApiResponse helper for consistent responses
|
|
482
|
+
- FileService for file operations
|
|
483
|
+
|
|
484
|
+
3. **Type Safety**
|
|
485
|
+
- Strong typing throughout
|
|
486
|
+
- FormRequest validation
|
|
487
|
+
- PHPDoc annotations
|
|
488
|
+
|
|
489
|
+
4. **Scalability**
|
|
490
|
+
- API versioning (V1, V2, ...)
|
|
491
|
+
- Query classes for complex logic
|
|
492
|
+
- Service layer pattern
|
|
493
|
+
|
|
494
|
+
5. **Maintainability**
|
|
495
|
+
- Clear folder structure
|
|
496
|
+
- Consistent naming
|
|
497
|
+
- Comprehensive documentation
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
## ๐ค AI Integration
|
|
502
|
+
|
|
503
|
+
This project is designed to work seamlessly with AI assistants.
|
|
504
|
+
|
|
505
|
+
### AI can help with:
|
|
506
|
+
1. **Generate migrations** - AI creates schema, you run gc:from-migration
|
|
507
|
+
2. **Complex queries** - AI understands Query class pattern
|
|
508
|
+
3. **Business logic** - AI knows where logic belongs (Query vs Controller)
|
|
509
|
+
4. **Validation rules** - AI writes comprehensive FormRequest rules
|
|
510
|
+
5. **Documentation** - AI generates PHPDoc for Scramble
|
|
511
|
+
|
|
512
|
+
### Example AI Workflow:
|
|
513
|
+
```
|
|
514
|
+
You: "Bikin API untuk e-commerce product dengan kategori dan brand"
|
|
515
|
+
|
|
516
|
+
AI: [generates complete migration with all relationships]
|
|
517
|
+
|
|
518
|
+
You: [saves migration]
|
|
519
|
+
php artisan gc:from-migration products
|
|
520
|
+
|
|
521
|
+
Result: Complete CRUD API with relationships ready!
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
**Read full guide:** [docs/AI-GUIDE-COMPLETE.md](docs/AI-GUIDE-COMPLETE.md)
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
## ๐งช Testing
|
|
529
|
+
|
|
530
|
+
```bash
|
|
531
|
+
# Run all tests
|
|
532
|
+
php artisan test
|
|
533
|
+
|
|
534
|
+
# Run specific test
|
|
535
|
+
php artisan test --filter=ProductTest
|
|
536
|
+
|
|
537
|
+
# With coverage
|
|
538
|
+
php artisan test --coverage
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
## ๐ Performance
|
|
544
|
+
|
|
545
|
+
**Generated APIs are optimized with:**
|
|
546
|
+
- โ
Eager loading (via `?include=`)
|
|
547
|
+
- โ
Pagination by default
|
|
548
|
+
- โ
Field selection (reduces payload)
|
|
549
|
+
- โ
Query caching (configurable)
|
|
550
|
+
- โ
Compressed images
|
|
551
|
+
- โ
Indexed foreign keys
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## ๐จ Important Notes
|
|
556
|
+
|
|
557
|
+
### DO NOT MODIFY
|
|
558
|
+
These files are part of the core framework:
|
|
559
|
+
- `app/Helpers/ApiResponse.php`
|
|
560
|
+
- `app/Traits/Queryable.php`
|
|
561
|
+
- `app/Services/FileService.php`
|
|
562
|
+
- `app/Http/Controllers/Controller.php`
|
|
563
|
+
|
|
564
|
+
### Safe to Customize
|
|
565
|
+
- Generated Controllers
|
|
566
|
+
- Generated Models
|
|
567
|
+
- Generated Requests
|
|
568
|
+
- Generated Query classes
|
|
569
|
+
- Routes
|
|
570
|
+
|
|
571
|
+
---
|
|
572
|
+
|
|
573
|
+
## ๐ Migration from Old Version
|
|
574
|
+
|
|
575
|
+
If migrating from version without Query classes:
|
|
576
|
+
|
|
577
|
+
1. **Backup your code**
|
|
578
|
+
2. **Update controllers** to use Query classes
|
|
579
|
+
3. **Add Queryable trait** to models
|
|
580
|
+
4. **Update routes** to use api_v1.php
|
|
581
|
+
5. **Test thoroughly**
|
|
582
|
+
|
|
583
|
+
---
|
|
584
|
+
|
|
585
|
+
## ๐ Benefits
|
|
586
|
+
|
|
587
|
+
### Before (Traditional)
|
|
588
|
+
- โฑ๏ธ 30+ minutes per CRUD module
|
|
589
|
+
- ๐ Manual coding prone to errors
|
|
590
|
+
- ๐ Inconsistent patterns
|
|
591
|
+
- ๐ Manual filtering logic
|
|
592
|
+
- ๐ Documentation gets outdated
|
|
593
|
+
|
|
594
|
+
### After (This Framework)
|
|
595
|
+
- โก 30 seconds per CRUD module
|
|
596
|
+
- โ
Zero errors (tested patterns)
|
|
597
|
+
- ๐ฏ 100% consistent
|
|
598
|
+
- ๐ Built-in advanced filtering
|
|
599
|
+
- ๐ Auto-generated docs
|
|
600
|
+
- ๐ค AI-powered workflow
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
## ๐ Example: Complete Product API
|
|
605
|
+
|
|
606
|
+
```bash
|
|
607
|
+
# 1. Create migration (or let AI generate it)
|
|
608
|
+
# 2. Run generator
|
|
609
|
+
php artisan gc:from-migration products
|
|
610
|
+
php artisan migrate
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
**Result:** You now have:
|
|
614
|
+
- โ
Full CRUD API
|
|
615
|
+
- โ
File upload with compression
|
|
616
|
+
- โ
Advanced filtering
|
|
617
|
+
- โ
Global search
|
|
618
|
+
- โ
Relationship loading
|
|
619
|
+
- โ
Validation
|
|
620
|
+
- โ
Auto documentation
|
|
621
|
+
- โ
Activity logging
|
|
622
|
+
|
|
623
|
+
**Test it:**
|
|
624
|
+
```bash
|
|
625
|
+
# List with filters
|
|
626
|
+
GET /api/v1/products?search=phone&sort=-price&paginate=20
|
|
627
|
+
|
|
628
|
+
# Create
|
|
629
|
+
POST /api/v1/products
|
|
630
|
+
{
|
|
631
|
+
"name": "iPhone 14",
|
|
632
|
+
"price": 15000000,
|
|
633
|
+
"image": (file upload)
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
# Update
|
|
637
|
+
PUT /api/v1/products/{id}
|
|
638
|
+
{
|
|
639
|
+
"price": 14000000
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
# Delete
|
|
643
|
+
DELETE /api/v1/products/{id}
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
---
|
|
647
|
+
|
|
648
|
+
## ๐ค Contributing
|
|
649
|
+
|
|
650
|
+
This is a base template for Laravel APIs. Feel free to customize for your projects.
|
|
651
|
+
|
|
652
|
+
---
|
|
653
|
+
|
|
654
|
+
## ๐ License
|
|
655
|
+
|
|
656
|
+
MIT License. See LICENSE for details.
|
|
657
|
+
|
|
658
|
+
---
|
|
659
|
+
|
|
660
|
+
## ๐ Credits
|
|
661
|
+
|
|
662
|
+
Built with:
|
|
663
|
+
- [Laravel](https://laravel.com)
|
|
664
|
+
- [Spatie Packages](https://spatie.be/open-source)
|
|
665
|
+
- [Scramble](https://scramble.dedoc.co)
|
|
666
|
+
|
|
667
|
+
---
|
|
668
|
+
|
|
669
|
+
## ๐ Support
|
|
670
|
+
|
|
671
|
+
For issues or questions, please check:
|
|
672
|
+
1. [STRUCTURE.md](STRUCTURE.md) - Project structure
|
|
673
|
+
2. [docs/AI-GUIDE-COMPLETE.md](docs/AI-GUIDE-COMPLETE.md) - Complete guide
|
|
674
|
+
3. Generated code comments
|
|
675
|
+
|
|
676
|
+
---
|
|
677
|
+
|
|
678
|
+
**๐ Happy Coding! Build APIs in seconds, not hours!**
|