Download the PHP package martinpham/laravel-type-generator without Composer

On this page you can find all versions of the php package martinpham/laravel-type-generator. 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-type-generator

TLDR: If you've ever wanted fully type-safe integration between your Laravel backend and your frontend (whether that's API consumers or Inertia.js apps), this package might save you a ton of time.

What It Does

The laravel-type-generator package scans your Laravel routes, controllers, models, DTOs, and their properties, methods, docblocks, and PHP source code. It then automatically generates:

(More transformers are coming soon!)

Think of it as a bridge that keeps your Laravel backend and frontend perfectly synchronized with types.

Installation

Publish the config:

Then run:

Configuration

The package is flexible. In the config file, you can customize what gets generated and where it goes. Here's a practical example showing how to generate:

Example: How Your Controller Becomes Typed API Specs

Let's say you have a simple controller method like this:

Here's what happens under the hood:

  1. The package analyzes the findUser method's input parameter (User $user) and return type (User).
  2. It automatically generates an OpenAPI operation for this route with $user as a parameter.
  3. It creates a User schema for both request and response types.
  4. Since your User model has relationships (like Address and Country), it recursively generates schemas for those related models too — so your OpenAPI spec and TypeScript types reflect the complete data structure.

This means your frontend gets fully typed models, including nested relationships, without any extra manual work!

OpenAPI

Seamless Integration with Orval for Type-Safe API Clients & Inertia template

Once laravel-type-generator creates your OpenAPI spec, you can feed it directly into Orval to automatically generate TypeScript types and API clients.

Here's what Orval would produce from the generated spec:

What this means for you:

This creates a tight feedback loop between your backend and frontend, boosting developer confidence and reducing bugs from mismatched data structures.

Inertia template

On Inertia side, you will receive exactly the types which were returned by the route

Inertia

Full Support for Various Data Types

The laravel-type-generator isn't limited to just Eloquent models. It also supports:

To give you more control over the generated OpenAPI spec, you can use special docblock annotations in your controller methods:

This flexibility lets you define complex return types with complete accuracy. For example:

Here's what's happening:

The package reads the docblocks and uses PHP's native type hints to generate detailed, nested TypeScript types and OpenAPI schemas.

Collections, paginated results, arrays with nested objects — everything gets parsed and converted correctly.

This means you can describe even very complex API responses in your controller methods and get fully typed clients on the frontend without any manual synchronization.

Specifying Request Parameters

Your API request parameters can come from different places, and laravel-type-generator supports all of them to generate accurate types:

1. Route Path Parameters

Simply define parameters in your route URL, like /users/{user}/. These will be automatically detected and typed.

2. FormRequest Subclasses

You can define a FormRequest class with typed properties and validation rules. The package inspects both your docblock properties and validation rules to generate the parameter types.

Example:

3. Docblock Annotations on Controller Methods

You can also specify request shapes directly in your controller method's docblocks using generics and param tags:

This tells the package exactly what your request parameters should look like, allowing for precise type generation.


All versions of laravel-type-generator with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ^8|^9|^10|^11|^12
phpdocumentor/reflection-docblock Version ^5.4
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 martinpham/laravel-type-generator contains the following files

Loading the files please wait ...