Download the PHP package baconfy/factory-payload without Composer

On this page you can find all versions of the php package baconfy/factory-payload. 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 factory-payload

Prompt

Tests Latest Version License Total Downloads PHP Version

Why?

When testing HTTP endpoints, you need request payloads that match the shape your endpoint expects, not the shape your model stores.

The simple case

Without this package:

With this package:

One line. Self-documenting. Reusable across every test that hits this endpoint.

When you need overrides

Sometimes you need to control specific fields, for example to test validation or assert against known values:

Overrides always pass through, even if the field isn't part of the model's stored attributes (useful for things like password_confirmation).

Installation

Requires PHP 8.3+ and Laravel 11, 12 or 13.

Usage

This package supports three equivalent ways to declare which attributes belong in the HTTP payload. Choose the style that best matches your project.

Using #[PayloadAttributes]

Declare the payload attributes directly on the factory class:

Using HasPayloadAttributes

Add the HasPayloadAttributes trait and define $payloadAttributes on your factory:

Both examples produce the same payload in your tests:

Notice how user_id and published_at are automatically excluded because they belong to persistence, not to the HTTP request.

Using a DTO class

If your project already declares request shapes through Data Transfer Objects (DTOs), you can resolve the payload shape directly from the DTO class. Useful when you have multiple endpoints (create, update, etc.) sharing the same model.

The DTO resolution follows these rules:

  1. If the class has a static keys(): array method, its return value is used as the whitelist (compatible with spatie/laravel-data and similar libraries).
  2. Otherwise, falls back to the class's public properties via Reflection:

If the class doesn't exist, an InvalidArgumentException is thrown with a clear message.

Note: When passing a DTO class, overrides are not supported in the same call. If you need both, use the array form: payload(['title' => 'custom']).

With Pest datasets

Test multiple invalid scenarios in one go:

Behavior

The behavior below applies to all three ways of declaring payload attributes:

Scenario Result
No payload attributes declared Returns only the overrides
#[PayloadAttributes] or $payloadAttributes declared Filters raw() by whitelist, then merges overrides
Override key exists in whitelist Override wins
Override key not in whitelist Override still passes through
Factory has count() set payload() still returns a single array
DTO class passed to payload() Resolves shape from keys() or public properties
Invalid DTO class passed Throws InvalidArgumentException

Testing

Credits

License

See LICENSE for details.


All versions of factory-payload with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/database 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 baconfy/factory-payload contains the following files

Loading the files please wait ...