Laravel PHP · Inline✓ Human-reviewed

App-owned static lookup in Laravel PHP

Inline one trusted read-only Sushi list while preserving exact string codes, referenced IDs, missing/empty distinctions and explicit resource policies.

Approved 2026-12-04T15:00:03.110858Z · Submission 90

App-owned static lookup in Laravel PHP

Scope

Inline one immutable, small Sushi model row set as explicit code/label values and one lookup. Preserve exact identities, ordering, missing results and public fields. Exclude dynamic getRows, user/remote/tenant data, mutations, query-builder emulation, relationships and model-backed validation rules. Keep those callers on the package path. Preserve the upstream MIT notice when adapting source. Check get-recipe's current port catalog when considering alternatives. This guidance has not been exercised in your app; verify it with the checks below.

Source behaviour

src/Sushi.php turns rows into a SQLite table, deriving schema from the first row with overrides, sometimes adding an incrementing primary key, and inserting in chunks. Numeric-looking strings can infer float columns, so the selected model's actual schema/casts matter. List position is not necessarily its externally observed ID.

Cache eligibility defaults to the presence of a rows property; cache freshness compares a reference file's modification time. An in-memory fallback also exists. These mechanisms do not guarantee durable writes or notice arbitrary external row-source updates. tests/SushiTest.php exercises schema, empty data, cache modes and relationships, but its same-cache-between-requests test is skipped.

Implementation

  1. Inventory row source, schema/casts, generated IDs, scopes/accessors, query/relationship/validation consumers, ordering and writes. Select only a trusted bounded list shipped with code. Preserve referenced IDs explicitly, even if the new data is reordered.
  2. Keep a list of code/label rows beside its owning feature. Validate the complete list before serving: unique exact string codes, non-null string labels, required fields and maximum size. PHP array keys can coerce numeric strings; keep codes as string values in rows and compare strictly. Do not let indexing silently overwrite duplicates.
  3. Replace only the chosen exact-code reader with an explicit lookup and existing missing-value mapping. Strict string matching deliberately differs from any SQLite coercion/collation used by the old query; compare real fixtures and preserve or accept the difference explicitly. Do not emulate arbitrary Eloquent methods or fabricate models just to preserve syntax.
  4. Retain authorization, tenant boundaries and resource fields. Only truly public tenant-independent values can be shared across requests; dynamic/request-owned data is outside this subset. Labels still need output-context escaping. No request can select a row file path or remote URL.
  5. This subset needs no SQLite file, migration, transaction or extra cache. Release data and code together and refresh long-lived workers. If data changes independently of deploys, retain its old path or design that persistence/invalidation separately. Do not delete cached SQLite or potentially durable data as part of the initial read cutover. Preserve other model consumers until migrated.

Complete pure lookup for a previously validated list of unique string-code/string-label rows. It deliberately uses strict comparison; a non-null empty string is a present result. Loading, duplicate validation, policies and response mapping are outside it:

function zoneLabel(array $zones, string $code): ?string
{
    foreach ($zones as $zone) {
        if ($zone['code'] === $code) {
            return $zone['label'];
        }
    }
    return null;
}

Use an app-owned method/name at the existing lookup boundary rather than adding a global helper solely to copy the example.

Acceptance checklist

  • With 01: North, 1: South, 10: "", assert distinct exact labels, a present empty label for 10, and null for 001, absent codes and an empty list. Do not use loose comparison or numeric-key coercion.
  • Reject duplicate/non-string codes, null/non-string labels and oversized lists during initialization. Preserve Unicode, explicit order and every externally referenced old ID.
  • Compare real schema/collation behavior, resources and not-found status. Retain still-used queries, scopes, accessors, relationships and model-backed validation rules.
  • Denied/cross-tenant requests cannot read scoped values through shared state. A refreshed worker sees a changed release without one request mutating another's list.
  • The selected read performs no database/network/file writes. Search getRows, Sushi trait/model references and composer why calebporzio/sushi before eventual dependency removal.

Run app lookup/resource/authorization tests and a worker-refresh rollout check, recording PHP/Laravel versions, outputs and deliberate differences. Pure string tests do not establish Eloquent query parity.

Sources

  • MIT reference source: src/Sushi.php and tests/SushiTest.php. Preserve LICENSE.md.
  • Framework source checked: src/Illuminate/Database/Eloquent/Model.php; replace model consumers deliberately and reconcile metadata with the app's lockfile. This lookup itself needs no Eloquent API.
  • Port options: check get-recipe's current port catalog (sourced from Package Port) at implementation time.