Download the PHP package abetwothree/laravel-ts-publish without Composer

On this page you can find all versions of the php package abetwothree/laravel-ts-publish. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-ts-publish

Generate TypeScript types from your Laravel models, enums, resources, routes & events

Latest Version on Packagist Laravel Compatibility GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is an extremely flexible package that allows you to transform Laravel PHP models, enums, API resources, routes, broadcast events, and other cast classes into TypeScript declaration types.

Enums & routes are treated as functional objects. Enums come with support for PHP-like enum functions and the inclusion of your custom methods in your enums.

Every Laravel application is different, and this package aims to provide the tools to tailor TypeScript types to your specific needs while providing powerful backend & frontend tooling to keep your frontend types in sync with your backend PHP code.

For examples of the generated TypeScript output, see these output examples.

Table of Contents

Installation

Requires PHP 8.4+ and supports Laravel 13, 12

Upgrading from version 1.x? Please refer to the Upgrade Guide for instructions on migrating from version 1.x to the current version.

You can install the package via composer:

You can publish the config file with:

Optionally, you can publish the views using:

Usage

Publishing Types

You can publish your TypeScript declaration types using the ts:publish Artisan command:

On first run, this package will intelligently cache files to make reruns significantly faster. You can break cache with the --fresh option. See Cache Generation for more details.

By default, the generated TypeScript declaration types will be saved to the resources/js/types/data/ directory and follow default configuration settings.

Additionally, by default, the package will look for content in the standard Laravel directories like app/Models, app/Enums, and app/Http/Resources. You can customize these settings in the published configuration file.

For a full installation and setup guide, see the Installation & Setup documentation.

Preview Mode

You can preview the generated TypeScript output in the console without writing any files by using --preview=true:

[!WARNING] The =true is required. --preview is declared with a default value ({--preview=false}), so a bare --preview flag is parsed as unset rather than true — the command will write real files instead of only previewing them.

This is useful for debugging or reviewing what will be generated before committing to file output.

Single-File Republishing

You can republish a single enum, model, or resource instead of the entire set by using the --source option with a fully-qualified class name or file path:

This is significantly faster than a full publish on large projects and is used automatically by the Vite plugin to republish only the file that changed during development.

Automatic Publishing After Migrations

By default, this package will automatically re-publish your TypeScript declaration types after running migrations. This ensures your TypeScript types stay in sync with your database schema changes.

You can disable this behavior in the config file or via environment variable:

Filtering Models, Enums & Resources

You can fully customize which content is included or excluded, and add additional directories to search in. By default, all content in standard Laravel directories like app/Models, app/Enums, app/Http/Resources are included.

Similar options are available for other content types like enums, events, resources, etc., allowing you to specify included, excluded, and additional_directories for each type.

[!TIP] Include and exclude settings accept both fully-qualified class names and directory paths. When a directory is provided, all matching classes within it will be discovered automatically.

Conditional Publishing

You can choose to publish only enums, only models, or only resources, either through configuration or command flags.

Via Configuration

Disable enum, model, or resource publishing entirely in the config file:

Setting any to false will skip that type on every run, including automatic post-migration publishing.

Via Command Flags

Use one of the --only-* flags to limit a single run to a specific type: --only-enums, --only-models, --only-resources, --only-routes, --only-form-requests, --only-broadcast-channels, or --only-broadcast-events.

These flags cannot be combined — passing any two together will return an error.

There's also --only-functional, which publishes only type-erasure-safe output (enums, routes, form requests, broadcast channels/events) while skipping models and resources — this is what the Vite plugin appends on vite build, since interfaces are erased at compile time anyway. It overrides the other --only-* flags if combined with them.

Config & Flag Conflicts

When a command flag requests a type that is disabled in config (e.g. --only-enums while enums.enabled is false), the command will prompt you to confirm whether to override the config setting. In non-interactive environments (CI, queued jobs, post-migration hooks), the config value is respected and the command exits gracefully.

If all types end up disabled (all config values are false and no override flag is given), the command prints a warning and exits with a success status.

Verbosity Levels

The ts:publish command supports three verbosity levels using the standard Artisan verbosity flags:

Flag Output
--quiet / -q No output at all — only the exit code indicates success or failure. Ideal for automated tooling like the Vite plugin.
(default) A compact summary showing the output directory, file counts, and any extra files generated (barrels, globals, JSON).
--verbose / -v Detailed tables listing every generated file with per-file metadata (cases, methods, columns, mutators, relations).

In quiet mode, files are still generated normally — only console output is suppressed. The Vite plugin passes --quiet by default since it only needs the exit code.

Enums

PHP enums are transformed into functional TypeScript objects — not just a union of values, but PHP-like behavior (.from(), .tryFrom(), .cases()) powered by @tolki/ts, plus any of your own enum methods and static methods can be included in the output.

Key capabilities:

For every attribute option, the metadata/@tolki/ts integration, the Vite plugin, and the full behavior of auto-including methods, see the full Enums documentation.

Models

Laravel Eloquent models are converted into TypeScript interfaces for their properties, mutators, and relations — split into focused interfaces by default so a page only needs to import the parts of a model it actually uses.

Key capabilities:

For the full template comparison, nullable relation strategies, every attribute option, and the complete type-mapping reference, see the full Models documentation.

API Resources

This package generates TypeScript interfaces from your Laravel API Resources (JsonResource classes) by statically analyzing the toArray() method — no need to hand-maintain a separate type for what your API already returns.

Key capabilities:

For every supported toArray() pattern, the full attribute reference, and nullable-relation strategies, see the full API Resources documentation.

Routes

This package publishes a lightweight, functional route helper for every controller action in your app — matching the feature set of Laravel Wayfinder, but with all the URL-building, parameter-binding, query-string, and form-spoofing logic tucked away inside a single defineRoute() factory from @tolki/ts instead of being generated inline for every route.

Key capabilities:

For every calling convention, model/enum binding rule, query-string behavior, route defaults, form-spoofing detail, and the Inertia/FormRequest typing helpers, see the full Routing documentation.

Form Requests

Laravel Form Request rules() methods are statically analyzed and converted into a TypeScript interface describing the request payload — no need to hand-maintain a separate type for what your validation rules already define.

Key capabilities:

For the full rule-to-type mapping, every JSDoc metadata annotation, and all attribute options, see the full Form Requests documentation.

Broadcast Channels

Every channel name registered in routes/channels.php is compiled into a single broadcast-channels.ts file — a BroadcastChannel template-literal type union, plus a BroadcastChannels const with a nested accessor function for every dynamic segment, so you never hand-type a {placeholder} channel string on the frontend.

Key capabilities:

For the dot-notation tree algorithm, parameter typing, and quoted-key handling, see the full Broadcast Channels documentation.

Broadcast Events

Every ShouldBroadcast / ShouldBroadcastNow event class gets its own TypeScript interface — generated from its broadcastWith() return shape, or its public constructor properties when there's no broadcastWith() — plus a combined broadcast-events.ts index with a BroadcastEvent union type and a flat BroadcastEvents const of every Echo event name.

Key capabilities:

For the full property-resolution rules, import-conflict aliasing, and Echo augmentation setup, see the full Broadcast Events documentation.

Inertia

When inertia.enabled is on, this package analyzes your HandleInertiaRequests middleware's share() method and generates inertia-config.d.ts — a module augmentation for @inertiajs/core plus a global Inertia.SharedData type, so every Inertia page automatically has fully-typed shared props with no manual typing.

Key capabilities:

For the full middleware discovery rules, the type-override priority order, and the generated file anatomy, see the full Inertia documentation.

Vite Env

When vite_env.enabled is on, this package reads the VITE_-prefixed variables from your .env (or .env.example) file and generates a vite-env.d.ts declaration file that augments Vite's ImportMetaEnv interface — so import.meta.env.VITE_APP_NAME is fully typed without hand-maintaining a separate declaration file.

Key capabilities:

For the exact variable-parsing rules and source-file resolution order, see the full Vite Env documentation.

Extending Interfaces with #[TsExtends] & Configs

Sometimes a generated interface needs to extend a hand-written TypeScript interface — for properties this package can't infer, or to share common fields across many models, resources, form requests, or broadcast events without duplication. The #[TsExtends] attribute (repeatable, and inherited from parent classes and traits) and the matching ts_extends.* config arrays both add to the generated interface's extends clause.

Key capabilities:

For the full attribute reference, the trait/parent-class inheritance rules, and how naming conflicts are resolved, see the full Extending Interfaces documentation.

Excluding with #[TsExclude]

The #[TsExclude] attribute excludes a specific enum, model, resource, form request, broadcast event, or controller — or one of their individual methods/accessors/relations/actions — from the TypeScript output. It's especially useful alongside enums.auto_include_methods / enums.auto_include_static_methods, letting you opt a single method back out of an otherwise-automatic inclusion.

The secretToken accessor above is entirely omitted from the generated User interface — everything else on the model still publishes normally.

Key capabilities:

For the full target reference and a worked example for every supported type, see the full Excluding Content documentation.

Casing Configurations

This package provides three independent config options to control the casing of generated property and method names — models.relationship_case for model relationship names, enums.method_case for enum method names, and routes.method_casing for route action names. All three accept 'snake', 'camel', or 'pascal'.

Key capabilities:

For the full casing tables and worked examples for all three settings, see the full Casing Configurations documentation.

JSON Enum HTTP API Resource

This package ships with EnumResource — a Laravel JSON resource that transforms any PHP enum case into a flat, API-friendly array, running it through the same transformer pipeline used for TypeScript publishing so every #[TsEnumMethod] / #[TsEnumStaticMethod] you've configured is automatically included in the response.

Key capabilities:

For the full response shape, unit enum behavior, and the auto-generated model resource interfaces, see the full Enum API Resource documentation.

Modular Publishing

Generated TypeScript files are always organized into namespace-derived directory trees that mirror your PHP namespace structure — there is no flat-output mode or config toggle to opt out of. This keeps output tidy for modular/domain-driven applications (e.g. InterNACHI/modular), while a single-namespace app (just App\Models, App\Enums, etc.) simply produces one app/ directory tree.

Key capabilities:

For the full kebab-casing algorithm, the relative-import-path rules, and the barrel file format, see the full Modular Publishing documentation.

Extending & Customizing the Pipeline

Every feature in this package runs through a Collector → Generator → Transformer → Writer → Template pipeline (or a subset of those stages — not every feature uses all five), and each stage is swappable per-feature via the config file. Extend the built-in class, override the matching config key, and the rest of the pipeline keeps working as-is.

Key capabilities:

For the full per-feature pipeline-stage reference, every abstract base class's method contract, and the cache rehydration mechanics, see the full Customizing the Pipeline documentation.

Pre-Command Hook

Register a closure with LaravelTsPublish::callCommandUsing() to run custom logic right before ts:publish executes — dynamically configuring directories, swapping pipeline classes, or reacting to feature flags. The closure only runs when the command actually runs, not at service provider boot time, so it never adds overhead to a normal request.

Key capabilities:

For worked examples (modular package integration, conditional pipeline swaps, feature-flag-driven publishing), the exact invocation timing, and how to safely reset the hook between tests, see the full Pre-Command Hook documentation.

Cache Generation

After the first full publish, ts:publish can skip re-generating classes whose source files (and everything they depend on) haven't changed. The cache is busted automatically whenever the package version or your output-affecting config changes, and a class is only served from cache if every file it previously wrote still exists on disk.

Key capabilities:

For the full fingerprinting algorithm, the dependency-recording rules, the ProvidesCacheSignature extension point for custom generators, and both storage backends' internals, see the full Cache Generation documentation.

Output Options

This package provides several output formats that can be enabled independently:

Config Key Default Description
output_to_files true Write individual .ts files with barrel index.ts exports
globals.enabled false Generate a global.d.ts file with a global TypeScript namespace
json.enabled false Output all generated definitions as a JSON file
watcher.enabled true Output a JSON list of collected PHP file paths (useful for file watchers)

When globals.enabled is enabled, a global declaration file is created that makes all your types available without explicit imports:

The JSON output from watcher.enabled is designed to work with build tools and file watchers (like the @tolki/ts Vite plugin) that need to know which PHP source files were collected so they can trigger a re-publish when those files change.

Configuration Reference

Every configuration option lives in config/ts-publish.php, organized by feature (models.*, enums.*, routes.*, cache.*, and so on). Publish the config file to customize any of it:

For the full list of every configuration key, its type, default, and description, see the complete Configuration Reference.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-ts-publish with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
composer/class-map-generator Version ^1.7.2
illuminate/contracts Version ^13.0||^12.0
laravel/prompts Version ^0.3.21
laravel/ranger Version ^0.1.12
laravel/surveyor Version ^0.1.9
nikic/php-parser Version ^5.0
spatie/laravel-package-tools Version ^1.16
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package abetwothree/laravel-ts-publish contains the following files

Loading the files please wait ...