Download the PHP package stubbedev/laravel-stoli without Composer
On this page you can find all versions of the php package stubbedev/laravel-stoli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stubbedev/laravel-stoli
More information about stubbedev/laravel-stoli
Files in stubbedev/laravel-stoli
Package laravel-stoli
Short Description An enhanced Laravel extension to export named routes to JavaScript, allowing you to use route names instead of URLs. Supports route grouping for modular applications. Provides type hinting for route params and responses.
License MIT
Informations about the package laravel-stoli
Laravel Stoli
stubbedev/laravel-stoli is a Laravel package that exports your application's named routes to TypeScript, enabling you to use route names instead of hardcoded URLs in your frontend code. It builds on top of spatie/laravel-data and spatie/laravel-typescript-transformer — both are required dependencies — and generates fully typed TypeScript definitions including parameter types inferred from FormRequest validation rules, URI constraint types, and response types derived from Data classes and the transformer's generated output.
Requirements
- PHP 8.2+
- Laravel 11.15+
spatie/laravel-data^3|^4spatie/laravel-typescript-transformer^3
Installation
Publish and configure spatie/laravel-typescript-transformer first — Stoli uses its output directory as the destination for all generated files:
Then publish the Stoli configuration:
Generate routes and types:
stoli:generate writes the following into the typescript-transformer output directory:
stoli.js— theRouteServiceruntimestoli.d.ts— TypeScript declarationsapi.ts(or one file per module) — typed route definitions
Usage
Basic
Typed parameters
The generated route file exports ApiRouteParams and ApiRouteName. URI parameters ({id}, {slug?}) are always included. When a controller method accepts a FormRequest, its validation rules are also included as typed fields.
URI constraint types
When routes declare ->where() constraints, the parameter type is narrowed accordingly:
Without a constraint the type is string | number. Optional parameters ({param?}) become param?: type.
FormRequest parameter types
Validation rules are reflected directly into TypeScript:
| Laravel rule | TypeScript type |
|---|---|
string, email, url, uuid, … |
string |
integer, numeric, decimal:… |
number |
boolean, accepted, declined |
boolean |
array |
Record<string, unknown> |
list, distinct |
unknown[] |
file, image |
File |
in:a,b,c / Rule::enum(MyEnum::class) |
'a' \| 'b' \| 'c' |
nullable modifier |
adds \| null |
Nested dot-notation (address.city) |
inline object type |
Wildcard arrays (tags.*) |
string[] / { … }[] |
Typed responses
Each generated module also exports ApiRouteResponse, a per-route map of response shapes. A route is included in the interface when its controller method has a return type annotation that is a Spatie\LaravelData\Data subclass and that class has been transformed by php artisan typescript:transform.
The generated interface looks like:
Routes without a resolvable Data return type are absent from the interface. The axios router (see below) falls back to Record<string, unknown> for those routes.
Spatie Laravel Data
Controllers returning Spatie\LaravelData\Data objects are detected automatically. The TypeScript shape is derived from the class's public typed properties:
Generates:
Supported property types:
| PHP type | TypeScript type |
|---|---|
int, float |
number |
string |
string |
bool |
boolean |
?type / type\|null |
type \| null |
Nested Data subclass |
inline object type |
DataCollection + #[DataCollectionOf(T::class)] |
T[] |
array + #[DataCollectionOf(T::class)] |
T[] |
DateTimeInterface |
string |
Collection |
unknown[] |
Spatie Laravel TypeScript Transformer
When php artisan typescript:transform has already been run, Stoli uses the generated type names directly instead of re-deriving inline shapes:
The import path is computed relative to the module's output directory. Always run typescript:transform before stoli:generate:
Axios router (optional)
Enable in config/stoli.php:
The generated router (api.router.ts) wraps axios with full type inference for both params and responses:
Requires axios: npm install axios
Route service methods
| Method | Description |
|---|---|
generateFullURL(name, params?) |
Full URL; leftover params are appended as query string |
createURLWithoutQuery(name, params?) |
URL with only URI params substituted; no query string |
has(name) |
Returns true if the route exists |
Configuration
Publish and edit config/stoli.php to customise.
All generated files are written to the output_path configured in config/typescript-transformer.php. Per-module path can override this for individual modules.
Module options
| Option | Default | Description |
|---|---|---|
match |
* |
URL prefix to filter routes. * matches all, /api/store matches only routes under that path |
name |
— | Output filename (without extension) |
rootUrl |
APP_URL |
Base URL for absolute URLs |
absolute |
true |
Generate absolute (https://…) or relative (/…) URLs |
prefix |
null |
Prefix prepended to every generated URL |
path |
transformer output dir | Output directory for this module's .ts file |
stripPrefix |
null |
Route name prefix to strip (e.g. store. turns store.products.list into products.list) |
Multiple modules
Split routes into separate typed files per API consumer:
This generates store.ts and admin.ts, each with their own StoreRouteParams / AdminRouteParams / StoreRouteResponse / AdminRouteResponse interfaces.
License
MIT. See license.
All versions of laravel-stoli with dependencies
laravel/framework Version ^v11.15|^12.0|^13.0
spatie/laravel-data Version ^3|^4
spatie/laravel-typescript-transformer Version ^3