Skip to content

docs(laravel): document booting without a database connection#2294

Open
soyuka wants to merge 1 commit into
api-platform:mainfrom
soyuka:docs/laravel-boot-without-database
Open

docs(laravel): document booting without a database connection#2294
soyuka wants to merge 1 commit into
api-platform:mainfrom
soyuka:docs/laravel-boot-without-database

Conversation

@soyuka

@soyuka soyuka commented Jun 11, 2026

Copy link
Copy Markdown
Member

What

Adds a Booting Without a Database Connection section to the Laravel guide (laravel/index.md).

Why

To expose an Eloquent model, API Platform reads its metadata (columns, types, relations, identifiers) directly from the database schema. This introspection runs while resource metadata is built, which happens at boot during route registration (routes/api.php iterates every resource) → ModelMetadata::getAttributes()$schema->getColumns() → a live DB query.

Consequence: the app cannot boot when no migrated database is reachable. This bites in common setups:

  • docker build (DB service not running);
  • composer install@php artisan package:discover;
  • static analysis (Larastan) in CI, which boots the app.

Reported in api-platform/core#8131.

What the section documents

  • the cause and the error users see;
  • workaround: migrated SQLite at build/analysis time;
  • Docker: SQLite during build, or defer metadata commands to the entrypoint (or composer install --no-scripts);
  • static analysis in CI: provision + migrate a SQLite DB before running PHPStan/Larastan.

Notes / follow-up

No code change. The cleaner long-term fix discussed in the issue — a dedicated artisan command that dumps computed metadata to a file-based store (committable / bakeable into the image) — does not exist in core/src/Laravel/Console yet. api-platform:install is not the right place for it (only publishes config/assets, runs without models/DB). When that command lands, this section should point to it.

Refs api-platform/core#8131

API Platform reads Eloquent metadata from the live database schema while
building resource metadata at boot (route registration, OpenAPI, caching).
The app therefore cannot boot when no migrated database is reachable, which
breaks Docker image builds, `composer install` (package:discover) and static
analysis (Larastan) in CI.

Add a section to the Laravel guide explaining the cause and the available
workarounds: using a migrated SQLite database at build time, deferring
metadata commands to the container entrypoint, and provisioning a database
for static analysis.

Refs api-platform/core#8131
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant