Add a flag to type bindings from model docblocks.

Merged
SW
5d ago
+7-0

Summary

Depends on laravel/wayfinder#331.

wayfinder:generate looks up route model binding types from the database schema. In private cloud build environments the database is not reachable, and Laravel retries the connection after it times out. Each distinct model therefore blocks for twice the connection timeout. A generate that should take about a minute can hang for more than 30 minutes.

That pull request adds a --model-docblocks option. When it is set, binding types are read from the Eloquent model's @property docblocks and the schema query is skipped, so generation never opens a database connection. Without the flag, behavior is unchanged: Wayfinder still queries the schema and falls back to the docblock only if that query throws.

This exposes that flag as a modelDocblocks option on the Vite plugin. It defaults to false. When it is true, --model-docblocks is passed on every generate, including the initial build and hot reloads. --skip-actions and --skip-routes are unchanged.

wayfinder({
    modelDocblocks: true,
})

Test plan

  • Generate with the default options and confirm the artisan command does not include --model-docblocks, and a model whose id column is an integer still types the parameter as number
  • Generate with modelDocblocks: true for a model whose docblock says @property string $id and confirm the command includes --model-docblocks and the parameter type is string
  • Generate with modelDocblocks: true alongside actions: false or routes: false and confirm --model-docblocks is still passed with --skip-actions or --skip-routes