Skip to main content
When developing a Laravel package that uses Laravel Data, you’ll need to ensure the package is properly configured for testing and usage.

Testing

When testing a package, you may encounter config access issues, especially with the magic from() factory method which requires config access to resolve the factory instance.

Orchestra Testbench Setup

Include the Laravel Data service provider in your package’s TestCase:

Complete Test Example

Publishing Config

If your package needs custom data configuration, publish a config file:

Create Package Config

Register in Service Provider

Package Structure

Recommended structure for packages using Laravel Data:

Composer Dependencies

Add Laravel Data to your package’s composer.json:

Example: Package Data Class

Testing Without Orchestra

If not using Orchestra Testbench, manually boot the service provider:
The Orchestra Testbench approach is recommended as it provides a full Laravel application environment for testing.