cc-codeconductor 0.2.10 → 0.3.1
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 +5 -4
- package/dist/index.js +1636 -1078
- package/package.json +1 -1
- package/presets/agy/AGENTS.md +46 -2
- package/presets/claude/CLAUDE.md +62 -2
- package/presets/claude/skills/android/SKILL.md +119 -0
- package/presets/claude/skills/laravel-specialist/SKILL.md +264 -0
- package/presets/claude/skills/laravel-specialist/references/eloquent.md +351 -0
- package/presets/claude/skills/laravel-specialist/references/livewire.md +512 -0
- package/presets/claude/skills/laravel-specialist/references/queues.md +423 -0
- package/presets/claude/skills/laravel-specialist/references/routing.md +362 -0
- package/presets/claude/skills/laravel-specialist/references/testing.md +522 -0
- package/presets/claude/skills/php-pro/SKILL.md +208 -0
- package/presets/claude/skills/php-pro/references/async-patterns.md +412 -0
- package/presets/claude/skills/php-pro/references/laravel-patterns.md +377 -0
- package/presets/claude/skills/php-pro/references/modern-php-features.md +323 -0
- package/presets/claude/skills/php-pro/references/symfony-patterns.md +466 -0
- package/presets/claude/skills/php-pro/references/testing-quality.md +466 -0
- package/presets/codex/AGENTS.md +47 -2
- package/presets/codex/skills/android/SKILL.md +119 -0
- package/presets/codex/skills/laravel-specialist/SKILL.md +264 -0
- package/presets/codex/skills/laravel-specialist/references/eloquent.md +351 -0
- package/presets/codex/skills/laravel-specialist/references/livewire.md +512 -0
- package/presets/codex/skills/laravel-specialist/references/queues.md +423 -0
- package/presets/codex/skills/laravel-specialist/references/routing.md +362 -0
- package/presets/codex/skills/laravel-specialist/references/testing.md +522 -0
- package/presets/codex/skills/php-pro/SKILL.md +208 -0
- package/presets/codex/skills/php-pro/references/async-patterns.md +412 -0
- package/presets/codex/skills/php-pro/references/laravel-patterns.md +377 -0
- package/presets/codex/skills/php-pro/references/modern-php-features.md +323 -0
- package/presets/codex/skills/php-pro/references/symfony-patterns.md +466 -0
- package/presets/codex/skills/php-pro/references/testing-quality.md +466 -0
- package/presets/opencode/agents/implementer.md +2 -2
- package/presets/opencode/agents/orchestrator.md +132 -5
- package/presets/opencode/agents/reviewer.md +33 -0
- package/presets/opencode/prompts/v0.3.0/architect.md +221 -0
- package/presets/opencode/prompts/v0.3.0/docs.md +189 -0
- package/presets/opencode/prompts/v0.3.0/implementer.md +162 -0
- package/presets/opencode/prompts/v0.3.0/orchestrator.md +360 -0
- package/presets/opencode/prompts/v0.3.0/repo-explorer.md +110 -0
- package/presets/opencode/prompts/v0.3.0/reviewer.md +225 -0
- package/presets/opencode/prompts/v0.3.0/task-coach.md +155 -0
- package/presets/opencode/prompts/v0.3.0/tester.md +251 -0
- package/presets/opencode/skills/android/SKILL.md +119 -0
- package/presets/opencode/skills/laravel-specialist/SKILL.md +264 -0
- package/presets/opencode/skills/laravel-specialist/references/eloquent.md +351 -0
- package/presets/opencode/skills/laravel-specialist/references/livewire.md +512 -0
- package/presets/opencode/skills/laravel-specialist/references/queues.md +423 -0
- package/presets/opencode/skills/laravel-specialist/references/routing.md +362 -0
- package/presets/opencode/skills/laravel-specialist/references/testing.md +522 -0
- package/presets/opencode/skills/php-pro/SKILL.md +208 -0
- package/presets/opencode/skills/php-pro/references/async-patterns.md +412 -0
- package/presets/opencode/skills/php-pro/references/laravel-patterns.md +377 -0
- package/presets/opencode/skills/php-pro/references/modern-php-features.md +323 -0
- package/presets/opencode/skills/php-pro/references/symfony-patterns.md +466 -0
- package/presets/opencode/skills/php-pro/references/testing-quality.md +466 -0
- package/src/presets/manifests/agy.yml +3 -2
- package/src/presets/manifests/claude.yml +3 -2
- package/src/presets/manifests/codex.yml +3 -2
- package/src/presets/manifests/cursor.yml +3 -2
- package/src/presets/manifests/gemini.yml +3 -2
- package/src/presets/manifests/opencode.yml +3 -2
- package/src/presets/models/opencode.yml +6 -6
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# Eloquent ORM
|
|
2
|
+
|
|
3
|
+
## Model Patterns
|
|
4
|
+
|
|
5
|
+
```php
|
|
6
|
+
<?php
|
|
7
|
+
|
|
8
|
+
namespace App\Models;
|
|
9
|
+
|
|
10
|
+
use Illuminate\Database\Eloquent\Model;
|
|
11
|
+
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
12
|
+
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
13
|
+
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
14
|
+
|
|
15
|
+
class Post extends Model
|
|
16
|
+
{
|
|
17
|
+
use HasFactory, SoftDeletes;
|
|
18
|
+
|
|
19
|
+
protected $fillable = [
|
|
20
|
+
'title',
|
|
21
|
+
'slug',
|
|
22
|
+
'content',
|
|
23
|
+
'published_at',
|
|
24
|
+
'user_id',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
protected $casts = [
|
|
28
|
+
'published_at' => 'datetime',
|
|
29
|
+
'metadata' => 'array',
|
|
30
|
+
'is_featured' => 'boolean',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
// Accessor using new Attribute syntax (Laravel 9+)
|
|
34
|
+
protected function title(): Attribute
|
|
35
|
+
{
|
|
36
|
+
return Attribute::make(
|
|
37
|
+
get: fn (string $value) => ucfirst($value),
|
|
38
|
+
set: fn (string $value) => strtolower($value),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Mutator for computed property
|
|
43
|
+
protected function excerpt(): Attribute
|
|
44
|
+
{
|
|
45
|
+
return Attribute::make(
|
|
46
|
+
get: fn () => str($this->content)->limit(100),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Relationships
|
|
53
|
+
|
|
54
|
+
```php
|
|
55
|
+
// One-to-Many
|
|
56
|
+
class User extends Model
|
|
57
|
+
{
|
|
58
|
+
public function posts(): HasMany
|
|
59
|
+
{
|
|
60
|
+
return $this->hasMany(Post::class);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public function latestPost(): HasOne
|
|
64
|
+
{
|
|
65
|
+
return $this->hasOne(Post::class)->latestOfMany();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public function oldestPost(): HasOne
|
|
69
|
+
{
|
|
70
|
+
return $this->hasOne(Post::class)->oldestOfMany();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class Post extends Model
|
|
75
|
+
{
|
|
76
|
+
public function user(): BelongsTo
|
|
77
|
+
{
|
|
78
|
+
return $this->belongsTo(User::class);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Inverse relationship
|
|
82
|
+
public function comments(): HasMany
|
|
83
|
+
{
|
|
84
|
+
return $this->hasMany(Comment::class);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Many-to-Many with Pivot
|
|
89
|
+
class User extends Model
|
|
90
|
+
{
|
|
91
|
+
public function roles(): BelongsToMany
|
|
92
|
+
{
|
|
93
|
+
return $this->belongsToMany(Role::class)
|
|
94
|
+
->withPivot('expires_at', 'assigned_by')
|
|
95
|
+
->withTimestamps()
|
|
96
|
+
->using(RoleUser::class); // Custom pivot model
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Has Many Through
|
|
101
|
+
class Country extends Model
|
|
102
|
+
{
|
|
103
|
+
public function posts(): HasManyThrough
|
|
104
|
+
{
|
|
105
|
+
return $this->hasManyThrough(Post::class, User::class);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Polymorphic Relations
|
|
110
|
+
class Image extends Model
|
|
111
|
+
{
|
|
112
|
+
public function imageable(): MorphTo
|
|
113
|
+
{
|
|
114
|
+
return $this->morphTo();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
class Post extends Model
|
|
119
|
+
{
|
|
120
|
+
public function images(): MorphMany
|
|
121
|
+
{
|
|
122
|
+
return $this->morphMany(Image::class, 'imageable');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Many-to-Many Polymorphic
|
|
127
|
+
class Tag extends Model
|
|
128
|
+
{
|
|
129
|
+
public function posts(): MorphToMany
|
|
130
|
+
{
|
|
131
|
+
return $this->morphedByMany(Post::class, 'taggable');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public function videos(): MorphToMany
|
|
135
|
+
{
|
|
136
|
+
return $this->morphedByMany(Video::class, 'taggable');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Query Scopes
|
|
142
|
+
|
|
143
|
+
```php
|
|
144
|
+
class Post extends Model
|
|
145
|
+
{
|
|
146
|
+
// Local scope
|
|
147
|
+
public function scopePublished($query): void
|
|
148
|
+
{
|
|
149
|
+
$query->whereNotNull('published_at')
|
|
150
|
+
->where('published_at', '<=', now());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public function scopePopular($query, int $threshold = 100): void
|
|
154
|
+
{
|
|
155
|
+
$query->where('views', '>=', $threshold);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Global scope
|
|
159
|
+
protected static function booted(): void
|
|
160
|
+
{
|
|
161
|
+
static::addGlobalScope('active', function ($query) {
|
|
162
|
+
$query->where('status', 'active');
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Usage
|
|
168
|
+
$posts = Post::published()->popular(500)->get();
|
|
169
|
+
|
|
170
|
+
// Custom Scope Class
|
|
171
|
+
namespace App\Models\Scopes;
|
|
172
|
+
|
|
173
|
+
use Illuminate\Database\Eloquent\Builder;
|
|
174
|
+
use Illuminate\Database\Eloquent\Model;
|
|
175
|
+
use Illuminate\Database\Eloquent\Scope;
|
|
176
|
+
|
|
177
|
+
class AncientScope implements Scope
|
|
178
|
+
{
|
|
179
|
+
public function apply(Builder $builder, Model $model): void
|
|
180
|
+
{
|
|
181
|
+
$builder->where('created_at', '<', now()->subYears(10));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Apply in model
|
|
186
|
+
protected static function booted(): void
|
|
187
|
+
{
|
|
188
|
+
static::addGlobalScope(new AncientScope);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Custom Casts
|
|
193
|
+
|
|
194
|
+
```php
|
|
195
|
+
namespace App\Casts;
|
|
196
|
+
|
|
197
|
+
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
|
198
|
+
|
|
199
|
+
class Money implements CastsAttributes
|
|
200
|
+
{
|
|
201
|
+
public function get($model, string $key, $value, array $attributes): float
|
|
202
|
+
{
|
|
203
|
+
return $value / 100; // Store cents, return dollars
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public function set($model, string $key, $value, array $attributes): int
|
|
207
|
+
{
|
|
208
|
+
return (int) ($value * 100);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// In model
|
|
213
|
+
protected $casts = [
|
|
214
|
+
'price' => Money::class,
|
|
215
|
+
];
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Query Optimization
|
|
219
|
+
|
|
220
|
+
```php
|
|
221
|
+
// Eager Loading (prevent N+1)
|
|
222
|
+
$posts = Post::with(['user', 'comments.user'])->get();
|
|
223
|
+
|
|
224
|
+
// Lazy Eager Loading
|
|
225
|
+
$posts = Post::all();
|
|
226
|
+
$posts->load('user');
|
|
227
|
+
|
|
228
|
+
// Eager Load with Constraints
|
|
229
|
+
$users = User::with(['posts' => function ($query) {
|
|
230
|
+
$query->where('published', true)->orderBy('created_at', 'desc');
|
|
231
|
+
}])->get();
|
|
232
|
+
|
|
233
|
+
// Count relationships efficiently
|
|
234
|
+
$posts = Post::withCount('comments')->get();
|
|
235
|
+
foreach ($posts as $post) {
|
|
236
|
+
echo $post->comments_count;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Exists checks
|
|
240
|
+
$users = User::withExists('posts')->get();
|
|
241
|
+
|
|
242
|
+
// Chunk for large datasets
|
|
243
|
+
Post::chunk(100, function ($posts) {
|
|
244
|
+
foreach ($posts as $post) {
|
|
245
|
+
// Process post
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Lazy collection for memory efficiency
|
|
250
|
+
Post::lazy()->each(function ($post) {
|
|
251
|
+
// Process one at a time
|
|
252
|
+
});
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Model Events
|
|
256
|
+
|
|
257
|
+
```php
|
|
258
|
+
class Post extends Model
|
|
259
|
+
{
|
|
260
|
+
protected static function booted(): void
|
|
261
|
+
{
|
|
262
|
+
static::creating(function ($post) {
|
|
263
|
+
$post->slug = str($post->title)->slug();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
static::updating(function ($post) {
|
|
267
|
+
if ($post->isDirty('title')) {
|
|
268
|
+
$post->slug = str($post->title)->slug();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
static::deleted(function ($post) {
|
|
273
|
+
$post->images()->delete();
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Using Observers
|
|
279
|
+
namespace App\Observers;
|
|
280
|
+
|
|
281
|
+
class PostObserver
|
|
282
|
+
{
|
|
283
|
+
public function creating(Post $post): void
|
|
284
|
+
{
|
|
285
|
+
$post->user_id = auth()->id();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
public function updated(Post $post): void
|
|
289
|
+
{
|
|
290
|
+
cache()->forget("post.{$post->id}");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Register in AppServiceProvider
|
|
295
|
+
use App\Models\Post;
|
|
296
|
+
use App\Observers\PostObserver;
|
|
297
|
+
|
|
298
|
+
public function boot(): void
|
|
299
|
+
{
|
|
300
|
+
Post::observe(PostObserver::class);
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Advanced Queries
|
|
305
|
+
|
|
306
|
+
```php
|
|
307
|
+
// Subqueries
|
|
308
|
+
$users = User::select(['id', 'name'])
|
|
309
|
+
->addSelect(['latest_post_title' => Post::select('title')
|
|
310
|
+
->whereColumn('user_id', 'users.id')
|
|
311
|
+
->latest()
|
|
312
|
+
->limit(1)
|
|
313
|
+
])->get();
|
|
314
|
+
|
|
315
|
+
// When conditional queries
|
|
316
|
+
$posts = Post::query()
|
|
317
|
+
->when($search, fn ($query) => $query->where('title', 'like', "%{$search}%"))
|
|
318
|
+
->when($category, fn ($query) => $query->where('category_id', $category))
|
|
319
|
+
->get();
|
|
320
|
+
|
|
321
|
+
// Database transactions
|
|
322
|
+
DB::transaction(function () {
|
|
323
|
+
$user = User::create([...]);
|
|
324
|
+
$user->profile()->create([...]);
|
|
325
|
+
$user->assignRole('member');
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Pessimistic locking
|
|
329
|
+
$user = User::where('id', 1)->lockForUpdate()->first();
|
|
330
|
+
|
|
331
|
+
// Upserts
|
|
332
|
+
User::upsert(
|
|
333
|
+
[
|
|
334
|
+
['email' => 'john@example.com', 'name' => 'John'],
|
|
335
|
+
['email' => 'jane@example.com', 'name' => 'Jane'],
|
|
336
|
+
],
|
|
337
|
+
['email'], // Unique columns
|
|
338
|
+
['name'] // Columns to update
|
|
339
|
+
);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Performance Tips
|
|
343
|
+
|
|
344
|
+
1. **Always eager load relationships** - Avoid N+1 queries
|
|
345
|
+
2. **Use chunking for large datasets** - Prevent memory exhaustion
|
|
346
|
+
3. **Index foreign keys** - Speed up joins
|
|
347
|
+
4. **Use select() to limit columns** - Reduce data transfer
|
|
348
|
+
5. **Cache expensive queries** - Use Redis/Memcached
|
|
349
|
+
6. **Use database indexing** - Add indexes in migrations
|
|
350
|
+
7. **Avoid using model events for heavy operations** - Use queues instead
|
|
351
|
+
8. **Use lazy collections** - For processing large datasets
|