Laravel Eloquent 12

Last reviewed Sep 24, 2026

Export as PDF

Prompt Details

Prompt Composition

3prompts
  1. PHP 8.4128 lines · 4.4K tokens
  2. Laravel 1259 lines · 1.6K tokens
  3. 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(), and find() 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 ungrouped orWhere() 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. Neither get() nor Model::all() supplies a result limit.
  • Use chunkById() or lazyById() 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 when cursor() would retain PDO-buffered results; cursor() also cannot eager load relationships. Enable Model::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