Laravel Eloquent 12
Last reviewed Sep 24, 2026
Prompt Details
Prompt Composition
3prompts
- PHP 8.4128 lines · 4.4K tokens
- Laravel 1259 lines · 1.6K tokens
- Laravel Eloquent 1272 lines · 3.2K tokens
Total259 lines · 9.2K tokens
CWE Coverage
- 20
- 22
- 59
- 78
- 79
- 89
- 95
- 98
- 117
- 187
- 201
- 208
- 209
- 214
- 252
- 256
- 295
- 307
- 323
- 338
- 340
- 352
- 354
- 367
- 384
- 390
- 409
- 434
- 470
- 502
- 522
- 532
- 552
- 601
- 611
- 613
- 614
- 639
- 674
- 732
- 770
- 776
- 798
- 807
- 829
- 862
- 863
- 915
- 916
- 918
- 940
- 942
- 1004
- 1275
- 1333
- 1395
Prompt Preview
Apply the Laravel 12 prompt first, including its PHP 8.4 baseline. These rules cover Laravel Eloquent 12 query construction, assignment and casts, scopes, relationships, model lifecycle, transactions, serialization, and database operation.
Query construction and bounded execution
- Validate the scalar or list shape expected by
where(),whereIn(), andfind()before passing input to them; reject an array where a single identifier is required instead of silently changing the query's meaning or result shape. - Group caller-controlled alternatives inside
where(function (...) { ... }), especially after relationship methods such as$user->posts(); an ungroupedorWhere()can escape the parent foreign-key condition or other mandatory predicates. - Allowlist relation and aggregate names exposed through
with(),load(),withCount(), and morph-loading APIs; cap relation depth, rows, columns, page sizes, and total query work. Neitherget()norModel::all()supplies a result limit. - Use
chunkById()orlazyById()when updating rows used by an iteration's filter, group existing alternatives before their added ID condition, and keep pagination keys and relationship keys stable during traversal. - Use bounded
lazy()batches for very large exports whencursor()would retain PDO-buffered results;cursor()also cannot eager load relationships. EnableModel::preventLazyLoading()in development and CI to expose unintended relationship queries.
Assignment, casts, and copied models
- Validate and allowlist both the lookup attributes and creation/update