cc-codeconductor 0.4.2 → 0.5.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 +75 -4
- package/dist/index.js +2698 -230
- package/package.json +1 -1
- package/presets/agy/skills/evaluation/SKILL.md +6 -0
- package/presets/agy/skills/openspec/SKILL.md +32 -0
- package/presets/agy/workflows/cc-openspec.md +62 -0
- package/presets/agy/workflows/cc-pipeline.md +69 -0
- package/presets/agy/workflows/cc-scorecard.md +17 -0
- package/presets/claude/commands/cc/openspec.md +144 -0
- package/presets/claude/commands/cc/review.md +13 -2
- package/presets/claude/commands/cc/scorecard.md +65 -0
- package/presets/claude/skills/evaluation/SKILL.md +42 -0
- package/presets/claude/skills/openspec/SKILL.md +54 -0
- package/presets/codex/AGENTS.md +57 -0
- package/presets/cursor/.cursorignore +15 -0
- package/presets/cursor/AGENTS.md +504 -0
- package/presets/cursor/agents/architect.md +211 -0
- package/presets/cursor/agents/complexity-auditor.md +76 -0
- package/presets/cursor/agents/contract-builder.md +75 -0
- package/presets/cursor/agents/docs.md +180 -0
- package/presets/cursor/agents/goal-planner.md +71 -0
- package/presets/cursor/agents/implementer.md +161 -0
- package/presets/cursor/agents/orchestrator.md +377 -0
- package/presets/cursor/agents/repo-explorer.md +100 -0
- package/presets/cursor/agents/reviewer.md +237 -0
- package/presets/cursor/agents/security-reviewer.md +113 -0
- package/presets/cursor/agents/task-coach.md +145 -0
- package/presets/cursor/agents/tester.md +241 -0
- package/presets/cursor/commands/cc/api-contract.md +58 -0
- package/presets/cursor/commands/cc/db-migration.md +58 -0
- package/presets/cursor/commands/cc/feature.md +115 -0
- package/presets/cursor/commands/cc/fix.md +121 -0
- package/presets/cursor/commands/cc/openspec.md +144 -0
- package/presets/cursor/commands/cc/pagespeed.md +103 -0
- package/presets/cursor/commands/cc/refactor.md +148 -0
- package/presets/cursor/commands/cc/review.md +137 -0
- package/presets/cursor/commands/cc/scorecard.md +65 -0
- package/presets/cursor/commands/cc/tdd-cycle.md +226 -0
- package/presets/cursor/commands/cc/test-plan.md +138 -0
- package/presets/cursor/rules/behavioral-discipline.mdc +14 -0
- package/presets/cursor/rules/context-budget.mdc +12 -0
- package/presets/cursor/rules/orchestration.mdc +12 -0
- package/presets/cursor/rules/yagni-stdlib.mdc +11 -0
- package/presets/cursor/skills/android/SKILL.md +122 -0
- package/presets/cursor/skills/api-versioning/SKILL.md +394 -0
- package/presets/cursor/skills/astro/SKILL.md +322 -0
- package/presets/cursor/skills/auth-token-inspector/SKILL.md +33 -0
- package/presets/cursor/skills/code-review/SKILL.md +208 -0
- package/presets/cursor/skills/conductor-setup/SKILL.md +127 -0
- package/presets/cursor/skills/django-orm/SKILL.md +463 -0
- package/presets/cursor/skills/django-testing/SKILL.md +417 -0
- package/presets/cursor/skills/django-uv/SKILL.md +409 -0
- package/presets/cursor/skills/drizzle-schema-architect/SKILL.md +54 -0
- package/presets/cursor/skills/evaluation/SKILL.md +8 -0
- package/presets/cursor/skills/fastapi-pydantic-strict/SKILL.md +46 -0
- package/presets/cursor/skills/find-skills/SKILL.md +144 -0
- package/presets/cursor/skills/jpa-nplusone-detector/SKILL.md +49 -0
- package/presets/cursor/skills/jpa-postgres/SKILL.md +626 -0
- package/presets/cursor/skills/laravel-specialist/SKILL.md +267 -0
- package/presets/cursor/skills/laravel-specialist/references/eloquent.md +351 -0
- package/presets/cursor/skills/laravel-specialist/references/livewire.md +512 -0
- package/presets/cursor/skills/laravel-specialist/references/queues.md +423 -0
- package/presets/cursor/skills/laravel-specialist/references/routing.md +362 -0
- package/presets/cursor/skills/laravel-specialist/references/testing.md +522 -0
- package/presets/cursor/skills/livewire-alpine-bridge/SKILL.md +39 -0
- package/presets/cursor/skills/multi-agent-orchestration/README.md +144 -0
- package/presets/cursor/skills/multi-agent-orchestration/SKILL.md +579 -0
- package/presets/cursor/skills/multi-agent-orchestration/examples/framework_implementations.py +362 -0
- package/presets/cursor/skills/multi-agent-orchestration/examples/orchestration_patterns.py +411 -0
- package/presets/cursor/skills/multi-agent-orchestration/scripts/agent_communication.py +334 -0
- package/presets/cursor/skills/multi-agent-orchestration/scripts/benchmarking.py +341 -0
- package/presets/cursor/skills/multi-agent-orchestration/scripts/workflow_management.py +334 -0
- package/presets/cursor/skills/nextjs-typescript/SKILL.md +394 -0
- package/presets/cursor/skills/openspec/SKILL.md +52 -0
- package/presets/cursor/skills/pagespeed-insights/SKILL.md +445 -0
- package/presets/cursor/skills/pagespeed-insights/reference.md +50 -0
- package/presets/cursor/skills/pagespeed-perf/SKILL.md +281 -0
- package/presets/cursor/skills/php-pro/SKILL.md +210 -0
- package/presets/cursor/skills/php-pro/references/async-patterns.md +412 -0
- package/presets/cursor/skills/php-pro/references/laravel-patterns.md +377 -0
- package/presets/cursor/skills/php-pro/references/modern-php-features.md +323 -0
- package/presets/cursor/skills/php-pro/references/symfony-patterns.md +466 -0
- package/presets/cursor/skills/php-pro/references/testing-quality.md +466 -0
- package/presets/cursor/skills/python/SKILL.md +613 -0
- package/presets/cursor/skills/python-django-stack/SKILL.md +500 -0
- package/presets/cursor/skills/python-fastapi-stack/SKILL.md +464 -0
- package/presets/cursor/skills/security/SKILL.md +384 -0
- package/presets/cursor/skills/seo-analytics-injector/SKILL.md +44 -0
- package/presets/cursor/skills/spring-auth-auditor/SKILL.md +33 -0
- package/presets/cursor/skills/spring-boot-feature/SKILL.md +566 -0
- package/presets/cursor/skills/spring-boot-kotlin/SKILL.md +408 -0
- package/presets/cursor/skills/spring-boot-testing-strategy/SKILL.md +479 -0
- package/presets/cursor/skills/sqlalchemy/SKILL.md +473 -0
- package/presets/cursor/skills/tailwind-responsive-auditor/SKILL.md +32 -0
- package/presets/cursor/skills/tdd-mutation-tester/SKILL.md +28 -0
- package/presets/cursor/skills/testing-tdd/SKILL.md +592 -0
- package/presets/cursor/skills/workflow-orchestration-patterns/SKILL.md +98 -0
- package/presets/cursor/skills/workflow-orchestration-patterns/references/details.md +223 -0
- package/presets/laravel-tall/agents/architect.md +8 -0
- package/presets/laravel-tall/agents/implementer.md +12 -0
- package/presets/laravel-tall/laravel-tall.yml +38 -0
- package/presets/opencode/agents/architect.md +153 -61
- package/presets/opencode/agents/complexity-auditor.md +1 -0
- package/presets/opencode/agents/contract-builder.md +93 -0
- package/presets/opencode/agents/docs.md +125 -40
- package/presets/opencode/agents/goal-planner.md +82 -0
- package/presets/opencode/agents/implementer.md +107 -38
- package/presets/opencode/agents/orchestrator.md +90 -71
- package/presets/opencode/agents/repo-explorer.md +1 -2
- package/presets/opencode/agents/reviewer.md +164 -75
- package/presets/opencode/agents/security-reviewer.md +129 -0
- package/presets/opencode/agents/task-coach.md +110 -59
- package/presets/opencode/agents/tester.md +1 -2
- package/presets/opencode/commands/cc-openspec.md +61 -0
- package/presets/opencode/commands/cc-scorecard.md +16 -0
- package/presets/opencode/prompts/v0.4.0/architect.md +221 -0
- package/presets/opencode/prompts/v0.4.0/complexity-auditor.md +89 -0
- package/presets/opencode/prompts/v0.4.0/docs.md +189 -0
- package/presets/opencode/prompts/v0.4.0/implementer.md +162 -0
- package/presets/opencode/prompts/v0.4.0/orchestrator.md +348 -0
- package/presets/opencode/prompts/v0.4.0/repo-explorer.md +110 -0
- package/presets/opencode/prompts/v0.4.0/reviewer.md +225 -0
- package/presets/opencode/prompts/v0.4.0/task-coach.md +155 -0
- package/presets/opencode/prompts/v0.4.0/tester.md +251 -0
- package/presets/opencode/prompts/v0.5.0/architect.md +222 -0
- package/presets/opencode/prompts/v0.5.0/complexity-auditor.md +91 -0
- package/presets/opencode/prompts/v0.5.0/contract-builder.md +84 -0
- package/presets/opencode/prompts/v0.5.0/docs.md +190 -0
- package/presets/opencode/prompts/v0.5.0/goal-planner.md +80 -0
- package/presets/opencode/prompts/v0.5.0/implementer.md +171 -0
- package/presets/opencode/prompts/v0.5.0/orchestrator.md +388 -0
- package/presets/opencode/prompts/v0.5.0/repo-explorer.md +111 -0
- package/presets/opencode/prompts/v0.5.0/reviewer.md +248 -0
- package/presets/opencode/prompts/v0.5.0/security-reviewer.md +123 -0
- package/presets/opencode/prompts/v0.5.0/task-coach.md +156 -0
- package/presets/opencode/prompts/v0.5.0/tester.md +252 -0
- package/presets/opencode/skills/auth-token-inspector/SKILL.md +31 -0
- package/presets/opencode/skills/drizzle-schema-architect/SKILL.md +51 -0
- package/presets/opencode/skills/evaluation/SKILL.md +6 -0
- package/presets/opencode/skills/fastapi-pydantic-strict/SKILL.md +44 -0
- package/presets/opencode/skills/jpa-nplusone-detector/SKILL.md +46 -0
- package/presets/opencode/skills/livewire-alpine-bridge/SKILL.md +36 -0
- package/presets/opencode/skills/openspec/SKILL.md +50 -0
- package/presets/opencode/skills/seo-analytics-injector/SKILL.md +44 -0
- package/presets/opencode/skills/spring-auth-auditor/SKILL.md +30 -0
- package/presets/opencode/skills/tailwind-responsive-auditor/SKILL.md +30 -0
- package/presets/opencode/skills/tdd-mutation-tester/SKILL.md +28 -0
- package/presets/python-data-api/agents/architect.md +8 -0
- package/presets/python-data-api/agents/implementer.md +9 -0
- package/presets/python-data-api/python-data-api.yml +37 -0
- package/presets/spring-kotlin-jpa/agents/architect.md +8 -0
- package/presets/spring-kotlin-jpa/agents/implementer.md +9 -0
- package/presets/spring-kotlin-jpa/spring-kotlin-jpa.yml +38 -0
- package/presets/templates/BACKLOG.md +33 -0
- package/presets/templates/execution-profile.yml +6 -0
- package/presets/templates/model-comparison.md +11 -0
- package/presets/templates/regression-checklist.yml +10 -0
- package/presets/ts-next-drizzle/agents/architect.md +8 -0
- package/presets/ts-next-drizzle/agents/implementer.md +10 -0
- package/presets/ts-next-drizzle/ts-next-drizzle.yml +41 -0
- package/src/presets/manifests/agy.yml +2 -2
- package/src/presets/manifests/claude.yml +2 -2
- package/src/presets/manifests/codex.yml +2 -2
- package/src/presets/manifests/cursor.yml +19 -3
- package/src/presets/manifests/gemini.yml +2 -2
- package/src/presets/manifests/opencode.yml +2 -2
- package/src/presets/models/agy.yml +21 -0
- package/src/presets/models/claude.yml +18 -0
- package/src/presets/models/codex.yml +18 -0
- package/src/presets/models/cursor.yml +39 -9
- package/src/presets/models/gemini.yml +18 -0
- package/src/presets/models/opencode.yml +18 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# Routing & API Resources
|
|
2
|
+
|
|
3
|
+
## Route Patterns
|
|
4
|
+
|
|
5
|
+
```php
|
|
6
|
+
// routes/web.php
|
|
7
|
+
use App\Http\Controllers\PostController;
|
|
8
|
+
use Illuminate\Support\Facades\Route;
|
|
9
|
+
|
|
10
|
+
// Resource routes
|
|
11
|
+
Route::resource('posts', PostController::class);
|
|
12
|
+
|
|
13
|
+
// API resource (excludes create/edit)
|
|
14
|
+
Route::apiResource('posts', PostController::class);
|
|
15
|
+
|
|
16
|
+
// Partial resource
|
|
17
|
+
Route::resource('posts', PostController::class)->only(['index', 'show']);
|
|
18
|
+
Route::resource('posts', PostController::class)->except(['destroy']);
|
|
19
|
+
|
|
20
|
+
// Nested resources
|
|
21
|
+
Route::resource('posts.comments', CommentController::class);
|
|
22
|
+
|
|
23
|
+
// Route groups
|
|
24
|
+
Route::prefix('admin')->middleware('auth')->group(function () {
|
|
25
|
+
Route::get('/dashboard', [DashboardController::class, 'index']);
|
|
26
|
+
Route::resource('users', UserController::class);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Named routes
|
|
30
|
+
Route::get('/posts/{post}', [PostController::class, 'show'])->name('posts.show');
|
|
31
|
+
|
|
32
|
+
// Route model binding
|
|
33
|
+
Route::get('/posts/{post:slug}', [PostController::class, 'show']);
|
|
34
|
+
|
|
35
|
+
// Multiple bindings
|
|
36
|
+
Route::get('/users/{user}/posts/{post:slug}', function (User $user, Post $post) {
|
|
37
|
+
return view('posts.show', compact('user', 'post'));
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API Routes
|
|
42
|
+
|
|
43
|
+
```php
|
|
44
|
+
// routes/api.php
|
|
45
|
+
use App\Http\Controllers\Api\V1\PostController;
|
|
46
|
+
|
|
47
|
+
Route::prefix('v1')->group(function () {
|
|
48
|
+
// Public routes
|
|
49
|
+
Route::get('/posts', [PostController::class, 'index']);
|
|
50
|
+
Route::get('/posts/{post}', [PostController::class, 'show']);
|
|
51
|
+
|
|
52
|
+
// Protected routes
|
|
53
|
+
Route::middleware('auth:sanctum')->group(function () {
|
|
54
|
+
Route::post('/posts', [PostController::class, 'store']);
|
|
55
|
+
Route::put('/posts/{post}', [PostController::class, 'update']);
|
|
56
|
+
Route::delete('/posts/{post}', [PostController::class, 'destroy']);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Rate limiting
|
|
61
|
+
Route::middleware('throttle:60,1')->group(function () {
|
|
62
|
+
Route::apiResource('posts', PostController::class);
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Controllers
|
|
67
|
+
|
|
68
|
+
```php
|
|
69
|
+
namespace App\Http\Controllers\Api;
|
|
70
|
+
|
|
71
|
+
use App\Http\Controllers\Controller;
|
|
72
|
+
use App\Http\Requests\StorePostRequest;
|
|
73
|
+
use App\Http\Requests\UpdatePostRequest;
|
|
74
|
+
use App\Http\Resources\PostResource;
|
|
75
|
+
use App\Http\Resources\PostCollection;
|
|
76
|
+
use App\Models\Post;
|
|
77
|
+
use Illuminate\Http\Response;
|
|
78
|
+
|
|
79
|
+
class PostController extends Controller
|
|
80
|
+
{
|
|
81
|
+
public function index()
|
|
82
|
+
{
|
|
83
|
+
$posts = Post::with('user')
|
|
84
|
+
->published()
|
|
85
|
+
->paginate(15);
|
|
86
|
+
|
|
87
|
+
return new PostCollection($posts);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public function store(StorePostRequest $request)
|
|
91
|
+
{
|
|
92
|
+
$post = Post::create($request->validated());
|
|
93
|
+
|
|
94
|
+
return new PostResource($post);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public function show(Post $post)
|
|
98
|
+
{
|
|
99
|
+
$post->load(['user', 'comments.user']);
|
|
100
|
+
|
|
101
|
+
return new PostResource($post);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public function update(UpdatePostRequest $request, Post $post)
|
|
105
|
+
{
|
|
106
|
+
$post->update($request->validated());
|
|
107
|
+
|
|
108
|
+
return new PostResource($post);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public function destroy(Post $post)
|
|
112
|
+
{
|
|
113
|
+
$post->delete();
|
|
114
|
+
|
|
115
|
+
return response()->noContent();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Form Requests
|
|
121
|
+
|
|
122
|
+
```php
|
|
123
|
+
namespace App\Http\Requests;
|
|
124
|
+
|
|
125
|
+
use Illuminate\Foundation\Http\FormRequest;
|
|
126
|
+
use Illuminate\Validation\Rule;
|
|
127
|
+
|
|
128
|
+
class StorePostRequest extends FormRequest
|
|
129
|
+
{
|
|
130
|
+
public function authorize(): bool
|
|
131
|
+
{
|
|
132
|
+
return true; // Or check user permissions
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public function rules(): array
|
|
136
|
+
{
|
|
137
|
+
return [
|
|
138
|
+
'title' => ['required', 'string', 'max:255'],
|
|
139
|
+
'slug' => ['required', 'string', 'unique:posts,slug'],
|
|
140
|
+
'content' => ['required', 'string'],
|
|
141
|
+
'category_id' => ['required', 'exists:categories,id'],
|
|
142
|
+
'tags' => ['array'],
|
|
143
|
+
'tags.*' => ['exists:tags,id'],
|
|
144
|
+
'published_at' => ['nullable', 'date', 'after:now'],
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public function messages(): array
|
|
149
|
+
{
|
|
150
|
+
return [
|
|
151
|
+
'title.required' => 'Please provide a post title',
|
|
152
|
+
'slug.unique' => 'This slug is already taken',
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Prepare data before validation
|
|
157
|
+
protected function prepareForValidation(): void
|
|
158
|
+
{
|
|
159
|
+
$this->merge([
|
|
160
|
+
'slug' => str($this->title)->slug(),
|
|
161
|
+
]);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
class UpdatePostRequest extends FormRequest
|
|
166
|
+
{
|
|
167
|
+
public function rules(): array
|
|
168
|
+
{
|
|
169
|
+
return [
|
|
170
|
+
'title' => ['sometimes', 'string', 'max:255'],
|
|
171
|
+
'slug' => [
|
|
172
|
+
'sometimes',
|
|
173
|
+
'string',
|
|
174
|
+
Rule::unique('posts', 'slug')->ignore($this->post)
|
|
175
|
+
],
|
|
176
|
+
'content' => ['sometimes', 'string'],
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## API Resources
|
|
183
|
+
|
|
184
|
+
```php
|
|
185
|
+
namespace App\Http\Resources;
|
|
186
|
+
|
|
187
|
+
use Illuminate\Http\Request;
|
|
188
|
+
use Illuminate\Http\Resources\Json\JsonResource;
|
|
189
|
+
|
|
190
|
+
class PostResource extends JsonResource
|
|
191
|
+
{
|
|
192
|
+
public function toArray(Request $request): array
|
|
193
|
+
{
|
|
194
|
+
return [
|
|
195
|
+
'id' => $this->id,
|
|
196
|
+
'title' => $this->title,
|
|
197
|
+
'slug' => $this->slug,
|
|
198
|
+
'excerpt' => $this->excerpt,
|
|
199
|
+
'content' => $this->when($request->route()->named('posts.show'), $this->content),
|
|
200
|
+
'published_at' => $this->published_at?->toISOString(),
|
|
201
|
+
'created_at' => $this->created_at->toISOString(),
|
|
202
|
+
|
|
203
|
+
// Relationships
|
|
204
|
+
'author' => new UserResource($this->whenLoaded('user')),
|
|
205
|
+
'comments' => CommentResource::collection($this->whenLoaded('comments')),
|
|
206
|
+
'comments_count' => $this->when($this->comments_count !== null, $this->comments_count),
|
|
207
|
+
|
|
208
|
+
// Conditional fields
|
|
209
|
+
'is_published' => $this->when($request->user()?->isAdmin(), $this->isPublished()),
|
|
210
|
+
|
|
211
|
+
// Pivot data
|
|
212
|
+
'role' => $this->whenPivotLoaded('role_user', function () {
|
|
213
|
+
return $this->pivot->role_name;
|
|
214
|
+
}),
|
|
215
|
+
|
|
216
|
+
// Links
|
|
217
|
+
'links' => [
|
|
218
|
+
'self' => route('api.posts.show', $this->id),
|
|
219
|
+
],
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public function with(Request $request): array
|
|
224
|
+
{
|
|
225
|
+
return [
|
|
226
|
+
'meta' => [
|
|
227
|
+
'version' => '1.0.0',
|
|
228
|
+
],
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Resource Collections
|
|
235
|
+
|
|
236
|
+
```php
|
|
237
|
+
namespace App\Http\Resources;
|
|
238
|
+
|
|
239
|
+
use Illuminate\Http\Request;
|
|
240
|
+
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
241
|
+
|
|
242
|
+
class PostCollection extends ResourceCollection
|
|
243
|
+
{
|
|
244
|
+
public function toArray(Request $request): array
|
|
245
|
+
{
|
|
246
|
+
return [
|
|
247
|
+
'data' => $this->collection,
|
|
248
|
+
'meta' => [
|
|
249
|
+
'total' => $this->total(),
|
|
250
|
+
'current_page' => $this->currentPage(),
|
|
251
|
+
'last_page' => $this->lastPage(),
|
|
252
|
+
],
|
|
253
|
+
'links' => [
|
|
254
|
+
'self' => $request->url(),
|
|
255
|
+
],
|
|
256
|
+
];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Or use anonymous collection
|
|
261
|
+
return PostResource::collection($posts);
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Middleware
|
|
265
|
+
|
|
266
|
+
```php
|
|
267
|
+
namespace App\Http\Middleware;
|
|
268
|
+
|
|
269
|
+
use Closure;
|
|
270
|
+
use Illuminate\Http\Request;
|
|
271
|
+
|
|
272
|
+
class EnsureUserIsAdmin
|
|
273
|
+
{
|
|
274
|
+
public function handle(Request $request, Closure $next)
|
|
275
|
+
{
|
|
276
|
+
if (!$request->user()?->isAdmin()) {
|
|
277
|
+
abort(403, 'Unauthorized action.');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return $next($request);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Register in app/Http/Kernel.php
|
|
285
|
+
protected $middlewareAliases = [
|
|
286
|
+
'admin' => \App\Http\Middleware\EnsureUserIsAdmin::class,
|
|
287
|
+
];
|
|
288
|
+
|
|
289
|
+
// Use in routes
|
|
290
|
+
Route::middleware('admin')->group(function () {
|
|
291
|
+
Route::resource('users', UserController::class);
|
|
292
|
+
});
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Response Helpers
|
|
296
|
+
|
|
297
|
+
```php
|
|
298
|
+
// JSON responses
|
|
299
|
+
return response()->json(['data' => $posts], 200);
|
|
300
|
+
|
|
301
|
+
// Created response
|
|
302
|
+
return response()->json($post, 201);
|
|
303
|
+
|
|
304
|
+
// No content
|
|
305
|
+
return response()->noContent();
|
|
306
|
+
|
|
307
|
+
// Custom headers
|
|
308
|
+
return response()->json($data)->header('X-Custom-Header', 'Value');
|
|
309
|
+
|
|
310
|
+
// Download
|
|
311
|
+
return response()->download($pathToFile);
|
|
312
|
+
|
|
313
|
+
// Stream
|
|
314
|
+
return response()->streamDownload(function () {
|
|
315
|
+
echo 'CSV content...';
|
|
316
|
+
}, 'export.csv');
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Route Caching
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
# Generate route cache
|
|
323
|
+
php artisan route:cache
|
|
324
|
+
|
|
325
|
+
# Clear route cache
|
|
326
|
+
php artisan route:clear
|
|
327
|
+
|
|
328
|
+
# List all routes
|
|
329
|
+
php artisan route:list
|
|
330
|
+
|
|
331
|
+
# Filter routes
|
|
332
|
+
php artisan route:list --name=api
|
|
333
|
+
php artisan route:list --path=posts
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## API Versioning
|
|
337
|
+
|
|
338
|
+
```php
|
|
339
|
+
// routes/api.php
|
|
340
|
+
Route::prefix('v1')->name('v1.')->group(function () {
|
|
341
|
+
Route::apiResource('posts', \App\Http\Controllers\Api\V1\PostController::class);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
Route::prefix('v2')->name('v2.')->group(function () {
|
|
345
|
+
Route::apiResource('posts', \App\Http\Controllers\Api\V2\PostController::class);
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## CORS Configuration
|
|
350
|
+
|
|
351
|
+
```php
|
|
352
|
+
// config/cors.php
|
|
353
|
+
return [
|
|
354
|
+
'paths' => ['api/*', 'sanctum/csrf-cookie'],
|
|
355
|
+
'allowed_methods' => ['*'],
|
|
356
|
+
'allowed_origins' => ['http://localhost:3000'],
|
|
357
|
+
'allowed_headers' => ['*'],
|
|
358
|
+
'exposed_headers' => [],
|
|
359
|
+
'max_age' => 0,
|
|
360
|
+
'supports_credentials' => true,
|
|
361
|
+
];
|
|
362
|
+
```
|