Skip to content

Upgrade Guide ​

Upgrading to 2.0 From 1.x ​

Version 2 aims to match everything Laravel Wayfinder provides, with a few things done differently.

New in Version 2 ​

Version 2 adds these features:

  • Route functions based on your routes and controllers, including return types for Inertia routes and Vue components, and pagination with the model or resource embedded automatically
  • Form request interfaces
  • Broadcast channels
  • Broadcast event interfaces
  • A Laravel Echo TypeScript augmentation
  • Global Inertia route response parameters
  • A Vite env augmentation file, built from the .env settings prefixed with VITE_
  • A generation cache that makes reruns of the full ts:publish command faster

Each feature's page in these docs shows the TypeScript it generates.

Follow these steps in order:

  1. Update to the v2 package release in Composer.
  2. Republish the config and views with --force. See Configuration Changes and Templates.
  3. Install @tolki/ts and remove @tolki/enum. See New npm Package.
  4. Update your Vite plugin import to @tolki/ts/vite.
  5. Remove your old generated data folder.
  6. Run a fresh publish with php artisan ts:publish --fresh.
  7. Fix the import paths in your app code to match the modular namespace output. See Modular Publishing Only.

Breaking Changes ​

Configuration Changes ​

The version 1 configuration was mostly flat. Version 2 has more features, so each main feature has its own config block.

Most version 1 settings move into their block, and the block name leaves the key: enum_template becomes enums.template, and publish_models becomes models.enabled.

If you published the config file, republish it with the --force flag:

bash
php artisan vendor:publish --tag="ts-publish-config" --force
Full Configuration Update List ​

The tables below map every key from the flat version 1 config to its version 2 block. The recommended path is to republish the config file, then use your project's git diff to find the customizations you need to reapply.

Show the Full Key-by-Key Migration Table
1) Pipeline Class Overrides Moved Under Each Feature Group ​
Old keyNew key
model_collector_classmodels.collector_class
model_generator_classmodels.generator_class
model_transformer_classmodels.transformer_class
model_writer_classmodels.writer_class
enum_collector_classenums.collector_class
enum_generator_classenums.generator_class
enum_transformer_classenums.transformer_class
enum_writer_classenums.writer_class
resource_collector_classresources.collector_class
resource_generator_classresources.generator_class
resource_transformer_classresources.transformer_class
resource_writer_classresources.writer_class
2) Shared Writer Overrides Renamed or Grouped ​
Old keyNew key
barrel_writer_classbarrel_writer_class (same key, still supported as a shared override)
globals_writer_classglobals.writer_class
json_writer_classjson.writer_class
watcher_json_writer_classwatcher.writer_class
3) Template Key Migration ​
Old keyNew key
model_templatemodels.template
enum_templateenums.template
resource_templateresources.template
globals_templateglobals.template

Version 2 also adds template keys for the new features:

New v2 template keys
routes.template
form_requests.template
broadcast_channels.template
broadcast_events.template
broadcast_events.index_template
broadcast_events.echo_augmentation.template
4) Feature Enable Flags Moved From Flat Keys to Grouped Keys ​
Old keyNew key
publish_enumsenums.enabled
publish_modelsmodels.enabled
publish_resourcesresources.enabled
output_globals_fileglobals.enabled
output_json_filejson.enabled
output_collected_files_jsonwatcher.enabled

Version 2 adds these feature toggles:

New v2 feature toggles
routes.enabled
form_requests.enabled
broadcast_channels.enabled
broadcast_events.enabled
inertia.enabled
vite_env.enabled
cache.enabled
5) Namespace and Casing Options Moved Under Feature Groups ​
Old keyNew key
models_namespacemodels.namespace
enums_namespaceenums.namespace
resources_namespaceresources.namespace
relationship_casemodels.relationship_case
enum_method_caseenums.method_case
nullable_relationsmodels.nullable_relations
relation_nullability_mapmodels.relation_nullability_map

The *.namespace keys have no effect in version 2. The globals file names each namespace after the class's PHP namespace, as described in Modular Publishing Only.

6) Include, Exclude, and Additional Directories Migrated Per Feature ​
Old keyNew key
additional_model_directoriesmodels.additional_directories
included_modelsmodels.included
excluded_modelsmodels.excluded
additional_enum_directoriesenums.additional_directories
included_enumsenums.included
excluded_enumsenums.excluded
additional_resource_directoriesresources.additional_directories
included_resourcesresources.included
excluded_resourcesresources.excluded

These new version 2 blocks use the same include, exclude, and additional directories pattern:

New v2 blocks using the same pattern
form_requests.*
broadcast_events.*
7) Enum Metadata and Options Renamed and Regrouped ​
Old keyNew key
enum_metadata_enabledenums.metadata_enabled
enums_use_tolki_packageenums.use_tolki_package
auto_include_enum_methodsenums.auto_include_methods
auto_include_enum_static_methodsenums.auto_include_static_methods
8) Output File Naming and Output Directory Keys Grouped ​
Old keyNew key
global_filenameglobals.filename
global_directoryglobals.output_directory
json_filenamejson.filename
json_output_directoryjson.output_directory
collected_files_json_filenamewatcher.filename
collected_files_json_output_directorywatcher.output_directory
9) Modular Publishing Setting Removed ​
Old keyStatus in v2
modular_publishingRemoved. Modular output is always on.
10) New Top-Level Config Groups in v2 ​

These blocks did not exist in the version 1 config:

New v2 top-level block
cache.*
routes.*
form_requests.*
broadcast_channels.*
broadcast_events.*
inertia.*
vite_env.*

Version 2 also adds this nested block:

New v2 nested block
broadcast_events.echo_augmentation.*
11) Keys That Stayed the Same ​

These keys are still top-level and need no migration:

KeyStatus
run_after_migrateUnchanged (still top-level)
output_to_filesUnchanged (still top-level)
output_directoryUnchanged (still top-level)
namespace_strip_prefixUnchanged (still top-level)
custom_ts_mappingsUnchanged (still top-level)
timestamps_as_dateUnchanged (still top-level)

ts_extends still exists, and version 2 adds sections beyond models and resources:

ts_extends keyv2 note
ts_extends.form_requestsNew section in v2
ts_extends.broadcast_eventsNew section in v2

New npm Package ​

To support functional routing as well as functional enums, install the new @tolki/ts package that goes with this Laravel package:

bash
npm install @tolki/ts

Then uninstall the previous @tolki/enum package. @tolki/ts supports both the version 1 functional enums and the new version 2 functional routing functions:

bash
npm uninstall @tolki/enum

If you use the Vite plugin, update its import path in your Vite config file:

typescript
import { laravelTsPublish } from "@tolki/ts/vite";

The build flag changed too. The Vite plugin from @tolki/enum calls ts:publish with the --only-enums option. The @tolki/ts Vite plugin calls it with --only-functional instead, which skips model and resource interfaces when building assets.

Templates ​

If you published and modified the Blade templates, publish them again and reapply your changes:

bash
php artisan vendor:publish --tag="laravel-ts-publish-views" --force

TsResourceCasts Attribute Removed ​

The TsResourceCasts attribute (AbeTwoThree\LaravelTsPublish\Attributes\TsResourceCasts) has been removed.

Replace every use with TsCasts (AbeTwoThree\LaravelTsPublish\Attributes\TsCasts), which now handles resources, trait methods, models, and form requests the same way. The constructor signature and array format are identical. Only the class name changes:

php
// Before
use AbeTwoThree\LaravelTsPublish\Attributes\TsResourceCasts;
#[TsResourceCasts(['field' => 'string'])]

// After
use AbeTwoThree\LaravelTsPublish\Attributes\TsCasts;
#[TsCasts(['field' => 'string'])]

Pipeline Customization ​

If you changed or extended a collector, generator, transformer, writer, or template in version 1, check that your changes still work with version 2. Then register your classes under the new *_class keys in each feature's block to override the package defaults. See Customizing the Pipeline.

Modular Publishing Only ​

In version 1, the default output was a flat directory, with a setting for modular publishing. Version 2 always publishes in the modular format, and there's no setting for a flat directory. With 7 large groups of features instead of 3, supporting both layouts was error-prone, so version 2 keeps only the modular one.

Update the import paths in your code to match the PHP namespace of each model, enum, and resource. Delete the data folder that holds your previous types, then run php artisan ts:publish --fresh, so the files you see match the version 2 output.

For example, take a model in this PHP namespace:

php
<?php

namespace App\Models\Users;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    //
}

Its import path changes like this:

typescript
// Before
import type { User } from "@data/models";

// After
import type { User } from "@data/app/models/users";

If you use the globals file, its namespaces follow your PHP namespaces too. A version 1 flat-mode type such as models.User becomes app.models.users.User for the model above. See Global Declaration File.

New Command Options and Behavior ​

Version 2 adds more selective ts:publish flags and a cache control:

bash
# Every enabled feature except model and resource interfaces
php artisan ts:publish --only-functional

# One feature at a time
php artisan ts:publish --only-routes
php artisan ts:publish --only-form-requests
php artisan ts:publish --only-broadcast-channels
php artisan ts:publish --only-broadcast-events

# Rebuild the cache
php artisan ts:publish --fresh

These flags follow three rules:

  • You can pass only one --only-* flag per command.
  • --only-functional takes precedence and ignores other --only-* flags.
  • --fresh forces a full regeneration and cache rebuild.

See Limiting a Single Run With Flags for every flag.

New Config Groups in v2 ​

Besides reorganizing the existing model, enum, and resource keys, version 2 adds these config blocks:

  • routes.*
  • form_requests.*
  • broadcast_channels.*
  • broadcast_events.*
  • inertia.*
  • vite_env.*
  • cache.*

If you published a version 1 config, republish it and reapply your customizations to the new block structure.

New Generated Files You Should Expect ​

Depending on which features are enabled, version 2 generates these files beyond enums, models, and resources:

  • Route controller helper files
  • Form request TypeScript interfaces
  • Event parameter TypeScript interfaces
  • broadcast-channels.ts
  • broadcast-events.ts
  • echo-broadcast-events.d.ts, when the Echo augmentation is enabled
  • inertia-config.d.ts
  • vite-env.d.ts, or your configured filename

Make sure your tsconfig.json include patterns cover these generated declaration files.

Generation Cache ​

Version 2 adds a generation cache that skips unchanged classes after the first run:

  • Run php artisan ts:publish --fresh after upgrading.
  • Use --fresh any time you need to guarantee a full rebuild.

See Cache Generation for how the cache works.

Released under the MIT License.