Download the PHP package dragosstoenica/laravel-zod without Composer

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

dragosstoenica/laravel-zod

Packagist Version PHP Version

Generate Zod 4 schemas from Laravel FormRequest classes (input) and Spatie laravel-data DTOs (output). PHP stays the source of truth; TypeScript gets runtime parsing and inferred types from a single file.

Compatibility: PHP 8.3 / 8.4 / 8.5 · Laravel 11 / 12 / 13 · Zod 4.x · Spatie Data 4.22+

Why this exists

Other generators have these problems:

Pattern Other generators This package
?UserData $host on a Data class inlined z.object({...}) (no schema reuse) host: UserDataSchema.nullable()
EventAttendeeData[] array inlined repeatedly z.array(EventAttendeeDataSchema)
Required string z.string({error}).trim().refine(...).min(1) (belt-and-suspenders) z.string().trim().min(1, '...')
Output schema dragged form-error messages type narrowing + nullability only ✓
Schema declaration order filenames or random topologically sorted ✓
Circular refs (self / mutual) TDZ error at runtime z.lazy(() => Schema) on back-edges ✓
Cross-field rules (after:other, required_if, …) partial / inline one .superRefine() block at schema bottom ✓
Locale hardcoded English --locale=ro + Laravel lang file fallback chain ✓

Install

The package's service provider auto-registers under Laravel's package discovery — no manual provider entry needed.

If you're consuming via a Composer path repository (recommended while iterating):

Usage

1. Mark classes with #[ZodSchema]

2. Generate

3. Consume from TypeScript

The generated file exports *Schema constants and *SchemaType aliases (the latter is a z.infer<> for convenience).

Configuration

config/laravel-zod.php:

Locales / messages

Resolution order, per (field, rule):

  1. FormRequest::messages() exact key'title.required' => 'Pick a name.'
  2. Wildcard'*.required' => ':attribute is mandatory.'
  3. Locale validation filelang/<locale>/validation.php (validation.required)
  4. English fallbacklang/en/validation.php
  5. Humanised fallbackHeadline-cased validation failed.

Placeholders filled: :attribute (from attributes() or the field name), :min, :max, :size, :other, :value, :date, :format, :digits, :decimal, :values.

For sub-keyed rules (min/max/between/size/gt/gte/lt/lte), the package picks the correct sub-key based on the field's inferred type:

To add a non-English locale:

Custom Rule classes

Any value in rules() can be a Rule object. Two ways the package handles them:

Opt-in: implement HasZodSchema

Stringifiable rules (e.g. Rule::in([...]), Rule::enum(MyEnum::class))

The package recognises Laravel's built-in stringifiable Rule objects and re-runs them through the rule translator.

Everything else

A custom Rule object that implements neither HasZodSchema nor a recognised __toString is skipped with a warning and a // custom rule skipped: … comment in the schema. Set 'custom_rules_strict' => true in the config to fail-loud instead.

Circular dependencies

Self-references (Comment.parent: ?Comment) and mutual references (Author.posts: Post[]Post.author: Author) are detected during topological sort. The back-edge gets wrapped in z.lazy(() => Schema) automatically:

You don't need to do anything in PHP — annotate the relations as plain nullable types (?UserData, ?array with @var X[]) and let the generator pick the right side to defer.

Rule coverage

All rules are translated to client-side Zod where the semantics map. Cross-field rules become .superRefine() blocks. DB-backed rules emit a // server-only comment.

Family Rules
Presence required, nullable, sometimes, present, filled, bail
Conditional presence required_if, required_unless, required_if_accepted, required_if_declined, required_with, required_with_all, required_without, required_without_all, required_array_keys
Missing / prohibited missing, missing_if, missing_unless, missing_with, missing_with_all, prohibited, prohibited_if, prohibited_if_accepted, prohibited_unless, prohibits
Exclusion exclude, exclude_if, exclude_unless, exclude_with, exclude_without
Accepted / declined accepted, accepted_if, declined, declined_if
Types string, integer, numeric, decimal, boolean, array, list, file, image, json
String constraints alpha, alpha_dash, alpha_num, ascii, lowercase, uppercase, starts_with, doesnt_start_with, ends_with, doesnt_end_with, contains, doesnt_contain, hex_color, regex, not_regex
Sized min, max, between, size (polymorphic — string length / numeric value / array length)
Numeric gt, gte, lt, lte (literal or field reference), multiple_of, digits, digits_between, max_digits, min_digits
Dates date, date_format, date_equals, after, after_or_equal, before, before_or_equal, timezone (handles now / today / tomorrow / yesterday aliases and field references)
Format email, url, active_url, uuid, ulid, ip, ipv4, ipv6, mac_address
Membership in, not_in, enum (resolves backed PHP enums to z.enum([...]))
Cross-field same, different, confirmed, in_array, distinct
File mimes, mimetypes, extensions, dimensions (server-side image-dim check is deferred with a comment)
Server-only exists, unique, current_password (skipped with comment)

Anything else triggers an Unhandled rule '<name>'… warning at generate time and is skipped.

Limitations

Honest list of what's not done:

Architecture

Two-pass generation:

  1. Discovery pass — walk scan paths, find every #[ZodSchema]-attributed class, register <FQN> → <ExportName> in the SchemaRegistry.
  2. Render pass — analyze each class (Data → reflection of typed props; FormRequest → rules() array fed through RuleTranslator), build an ObjectSchema, topologically sort with cycle detection, mark back-edges with useLazyReference, render.

Contributing

Bug reports and PRs welcome. Things that would be useful next:

License

MIT.


All versions of laravel-zod with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/console Version ^11.0|^12.0|^13.0
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/translation Version ^11.0|^12.0|^13.0
illuminate/validation Version ^11.0|^12.0|^13.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 dragosstoenica/laravel-zod contains the following files

Loading the files please wait ...