Download the PHP package oybek-daniyarov/laravel-trpc without Composer

On this page you can find all versions of the php package oybek-daniyarov/laravel-trpc. 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-trpc

Laravel tRPC

Latest Version on Packagist Total Downloads License

Generate a fully typed TypeScript client from your Laravel routes — with request types, response types, and optional React Query/Inertia helpers.

Quick Example

What This Is (and Isn't)

What it is: A Laravel-first generator that inspects your routes and produces a TypeScript client with fully typed inputs and outputs.

What it isn't: This is not a server-side implementation of the tRPC protocol. It doesn't require a Node.js tRPC router. It generates a typed HTTP client for your existing Laravel routes.

Runtime model: Generation happens at build time via php artisan trpc:generate. The output is a small TypeScript client that calls your HTTP endpoints — no runtime reflection on the PHP side.

Status

Beta (0.x). The public API and generated output structure may change between minor versions. For production use:

Features

Example Project

See it in action — a Laravel API with Inertia.js frontend, fully typed end-to-end:

🔗 github.com/oybek-daniyarov/empty-space

Table of Contents

Requirements

Installation

Publish the config file:

Quick Start

1. Define Data Classes

2. Add TypedRoute Attribute to Controllers

TypedRoute Attribute

The #[TypedRoute] attribute explicitly declares request and response types for your API endpoints. When applied, it takes priority over static analysis for type detection.

Parameters

Parameter Type Description
request class-string\|null Request body Data class (for POST/PUT/PATCH)
query class-string\|null Query parameters Data class (for GET requests)
response class-string\|null Response Data class
errorResponse class-string\|null Error response Data class (defaults to ValidationError)
isCollection bool Response is an array of items (Array<T>)
isPaginated bool Response is paginated (PaginatedResponse<T>)

Examples

Basic response type:

Request and response types:

Query parameters (for GET with filters/search):

Paginated response:

Collection response (non-paginated array):

No response body (204 No Content):

Custom error response:

Query vs Request

Generate & Use

Generate TypeScript Client

4. Use in TypeScript

Generated Files

The generator produces a tree-shakeable folder structure:

Tree-Shaking

Import only what you need for optimal bundle size:

Output Contract

The generator produces a stable folder structure:

Naming Conventions

Configuration

Configuration Reference

Option Type Default Description
output_path string resource_path('js/api') Directory for generated TypeScript files
api_prefix string 'api' API route prefix for filtering
version string 'v1' API version identifier
route_mode string 'api' Route collection mode (see below)
include_patterns array [] Route patterns to include
exclude_patterns array [...] Route patterns to exclude
exclude_methods array ['options', 'head'] HTTP methods to skip
preset string|null null Framework preset: 'inertia', 'api', 'spa'
outputs array [...] Files to generate
auto_typescript_transform bool true Auto-run typescript:transform
laravel_types_path string|null null Path to laravel.d.ts

Route Modes

Mode Description
'api' Only routes starting with api_prefix (default)
'web' Only routes NOT starting with api_prefix
'all' All routes (use with include/exclude patterns)
'named' Only routes with names
'attributed' Only routes with #[TypedRoute] attribute

Presets

Use presets to quickly enable common output configurations:

Preset Enables Use Case
'inertia' Core files + Inertia helpers Laravel + Inertia.js apps
'api' Core files + React Query + Mutations API-first / SPA with React Query
'spa' Core files + Inertia + React Query + Mutations Full-featured SPA
null Custom (configure outputs manually) Fine-grained control

Presets override the outputs array. To customize individual outputs, set preset to null and configure outputs directly.

Postman Configuration

Middleware Configuration

Control how middleware appears in the generated TypeScript output:

Before (with short_names: false and no exclusions):

After (with short_names: true and Tenancy excluded):

Middleware Input Short Name Output
Stancl\Tenancy\Middleware\InitializeTenancyByDomain InitializeTenancyByDomain
App\Http\Middleware\RateLimiter:api RateLimiter:api
auth:sanctum auth:sanctum (unchanged)
web web (unchanged)

Middleware & Authentication

The generated routes include middleware information, allowing you to build auth-aware UIs.

Generated Route Data

Each route includes middleware and authentication info:

Type Helpers for Auth Routes

Filter routes by authentication requirement:

Checking Auth Before API Calls

Accessing Middleware Array

Error Handling

Built-in Error Types

The generated types.ts includes standard Laravel error types:

Custom Error Types with errorResponse

Define custom error Data classes for specific routes:

Using Error Types in TypeScript

Error Handling with React Query

Type Helpers

Extract types from route names for use in your components:

React Query Integration

Enable in config:

Generated Files

File Description
react-query.ts Low-level utilities: queryKey, createQueryOptions, createInfiniteQueryOptions
queries.ts Resource-based query factories organized by API resource (e.g., usersQueries, postsQueries)
mutations.ts Resource-based mutation factories organized by API resource (e.g., usersMutations, postsMutations)

Setup

Before using queries and mutations, create configured instances in a setup file:

Then import from your setup file in components:

Resource-Based Queries (queries.ts)

The queries.ts file generates query factories for each API resource, providing:

Low-Level Utilities (react-query.ts)

For more control, use the low-level utilities:

Full Example

Infinite Queries for Pagination

Paginated endpoints automatically generate infiniteQueryOptions:

Resource-Based Mutations (mutations.ts)

The mutations.ts file generates type-safe mutation factories for POST, PUT, PATCH, and DELETE endpoints:

Mutation keys for cache management:

Inertia.js Integration

API Client Configuration

Basic Setup

Create a configured API instance and export it for use throughout your app:

Usage

Per-Request Options

All API methods accept an optional RequestOptions object as the last parameter:

Next.js App Router

Server Components

Server Actions

Route Handlers

React Query Integration

With Configured API (Recommended)

Use createQueries to bind queries to a configured API instance:

Command Options

Command Options Reference

Option Description
--output=PATH Override the output directory from config
--api-prefix=PREFIX Override the API route prefix filter
--skip-typescript-transform Skip auto-running typescript:transform
--postman Generate Postman collection only (shorthand for --format=postman)
--postman-env Also generate Postman environment file
--format=FORMAT Output format: typescript (default), postman, or all
--force Overwrite existing files without confirmation
--base-url=URL Set default base URL for the generated TypeScript client

Customizing Stubs

Publish the stub templates:

Templates will be copied to resources/views/vendor/trpc/.

Known Limitations

Troubleshooting

"No API routes found"

Generated types are unknown

TypeScript errors after regeneration

Route names are duplicated

Versioning

This package follows Semantic Versioning:

During the 0.x beta period, minor versions may include breaking changes. These will be clearly documented in the CHANGELOG.

Backstory

I built this to solve a real problem: getting a strongly typed TypeScript client from Laravel routes without manual type duplication.

I used AI tooling (Claude Code) to accelerate development — it helped with boilerplate, iteration, and exploration. The architecture and direction were mine; the implementation was collaborative.

The package has 250+ passing tests, PHPStan level 8 analysis, and is used in production projects. I'm sharing it because it works and saves time.

Found a bug? Open an issue. I'll fix it.

License

MIT License. See LICENSE for details.

Credits


All versions of laravel-trpc with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
laravel/framework Version ^11.0|^12.0|^13.0
laravel/ranger Version 0.1.*
laravel/surveyor Version 0.1.*
spatie/laravel-data Version ^4.0
spatie/laravel-typescript-transformer Version ^3.0
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 oybek-daniyarov/laravel-trpc contains the following files

Loading the files please wait ...