> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Develop Laravel packages with Testbench Workbench

> Use Orchestra Testbench Workbench to build a realistic package development environment with routes, migrations, and a local app runtime.

## What is Testbench Workbench?

[Orchestra Testbench](https://github.com/orchestral/testbench) is focused on automated tests. With Workbench, you also get a small Laravel app inside your package repository for interactive development.

Use it as a continuation of `package-testing` when you need UI checks, route verification, and seeded integration scenarios.

```mermaid theme={null}
flowchart TD
    A["Package code<br>`src/`"] --> B["Workbench<br>`workbench/`"]
    B --> C["WorkbenchServiceProvider<br>demo service registration"]
    B --> D["Routes and controllers<br>interactive checks"]
    B --> E["Migrations and seeders<br>realistic data"]
    B --> F["`composer serve`<br>local runtime"]
    C --> G["testbench.yaml<br>providers / build config"]
```

## Setup

<Steps>
  <Step title="Install Testbench">
    ```bash theme={null}
    composer require --dev orchestra/testbench
    ```
  </Step>

  <Step title="Install Workbench scaffold">
    ```bash theme={null}
    vendor/bin/testbench workbench:install
    ```

    This command does the following in one step:

    * Creates the `workbench/` directory structure
    * Adds Workbench namespaces to `composer.json` `autoload-dev`
    * Adds build scripts to `composer.json` `scripts`

    <Tip>
      Additional options:

      * `--force`: overwrite existing files
      * `--basic`: minimal setup without routes and package discovery configuration
      * `--devtool`: enable DevTool support
    </Tip>
  </Step>

  <Step title="Build and serve">
    ```bash theme={null}
    composer clear
    composer prepare
    composer build
    vendor/bin/testbench serve
    ```
  </Step>
</Steps>

<Info>
  `workbench:install` prepares the `workbench/` tree, `autoload-dev`, and related scripts in one step.
</Info>

After installation, `composer.json` includes the following:

```json theme={null}
{
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/",
            "Workbench\\App\\": "workbench/app/",
            "Workbench\\Database\\Factories\\": "workbench/database/factories/",
            "Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "@clear",
            "@prepare"
        ],
        "clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
        "prepare": "@php vendor/bin/testbench package:discover --ansi",
        "build": "@php vendor/bin/testbench workbench:build --ansi",
        "serve": [
            "Composer\\Config::disableProcessTimeout",
            "@build",
            "@php vendor/bin/testbench serve --ansi"
        ]
    }
}
```

## Define your environment in testbench.yaml

Use `testbench.yaml` in the package root to control providers, migrations, and build steps.

<Warning>
  `testbench.yaml` often contains environment-specific settings. Add it to `.gitignore` and keep a `testbench.yaml.example` template in the repository for other developers.
</Warning>

```yaml theme={null}
providers:
  - Vendor\Package\PackageServiceProvider
  - Workbench\App\Providers\WorkbenchServiceProvider

migrations:
  - workbench/database/migrations

workbench:
  start: '/'
  install: true
  health: false
  discovers:
    web: true
    api: false
    commands: false
    components: false
    views: false
    config: true
  build:
    - asset-publish
    - create-sqlite-db
    - db-wipe
    - migrate-fresh:
        --seed: true
        --seeder: Workbench\Database\Seeders\DatabaseSeeder
  assets:
    - laravel-assets
```

Key configuration options:

| Key                   | Description                                            |
| --------------------- | ------------------------------------------------------ |
| `providers`           | Service providers to load in the Workbench environment |
| `migrations`          | Migration directories to run                           |
| `workbench.start`     | Default URL when running `composer serve`              |
| `workbench.discovers` | Control Laravel package auto-discovery                 |
| `workbench.build`     | Commands to run during the build step                  |

You can also set environment variables in `testbench.yaml`:

```yaml theme={null}
env:
  - APP_ENV=testing
  - APP_KEY=base64:your-app-key
  - DB_CONNECTION=sqlite
  - DB_DATABASE=:memory:
```

## Workbench directory structure

<Tree>
  <Tree.Folder name="workbench" defaultOpen>
    <Tree.Folder name="app" defaultOpen>
      <Tree.Folder name="Http">
        <Tree.Folder name="Controllers" />
      </Tree.Folder>

      <Tree.Folder name="Models" />

      <Tree.Folder name="Providers">
        <Tree.File name="WorkbenchServiceProvider.php" />
      </Tree.Folder>
    </Tree.Folder>

    <Tree.Folder name="bootstrap" />

    <Tree.Folder name="config" />

    <Tree.Folder name="database" defaultOpen>
      <Tree.Folder name="factories" />

      <Tree.Folder name="migrations" />

      <Tree.Folder name="seeders">
        <Tree.File name="DatabaseSeeder.php" />
      </Tree.Folder>
    </Tree.Folder>

    <Tree.Folder name="public" />

    <Tree.Folder name="resources">
      <Tree.Folder name="views" />
    </Tree.Folder>

    <Tree.Folder name="routes">
      <Tree.File name="web.php" />

      <Tree.File name="api.php" />

      <Tree.File name="console.php" />
    </Tree.Folder>

    <Tree.Folder name="storage" />
  </Tree.Folder>
</Tree>

## Core features Workbench gives you

### WorkbenchServiceProvider

Create a service provider to register Workbench-specific services and wire up demo routes and views.

```php theme={null}
<?php

namespace Workbench\App\Providers;

use Illuminate\Support\ServiceProvider;
use Vendor\Package\SomeClass;
use Workbench\App\Services\DemoService;

class WorkbenchServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(DemoService::class);
    }

    public function boot(): void
    {
        SomeClass::register('demo', DemoService::class);
        $this->loadRoutesFrom(__DIR__.'/../../routes/web.php');
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'workbench');
    }
}
```

### Routes and controllers

Place development routes in `workbench/routes/web.php` and `workbench/routes/api.php` so you can verify package behavior from a browser or HTTP client.

```php theme={null}
use Illuminate\Support\Facades\Route;
use Vendor\Package\Facades\Package;

Route::get('/', function () {
    return Package::status();
});
```

### Migrations and seeders

Use `workbench/database/migrations` and `workbench/database/seeders` to test your package against realistic schema and data.

```php theme={null}
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Schema::create('widgets', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->timestamps();
});
```

Populate test data with a seeder:

```php theme={null}
<?php

namespace Workbench\Database\Seeders;

use Illuminate\Database\Seeder;
use Workbench\Database\Factories\UserFactory;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        UserFactory::new()->count(10)->create();
    }
}
```

### Local runtime and console workflows

Run Artisan commands through `vendor/bin/testbench`.

```bash theme={null}
vendor/bin/testbench list
vendor/bin/testbench route:list
vendor/bin/testbench migrate:fresh --seed
```

## Testing with the WithWorkbench trait

Use the `WithWorkbench` trait to apply `testbench.yaml` configuration to your automated test suite.

```php theme={null}
<?php

namespace Tests;

use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
{
    use WithWorkbench;

    protected function getPackageProviders($app): array
    {
        return [
            \Vendor\Package\Providers\YourServiceProvider::class,
        ];
    }

    protected function defineEnvironment($app): void
    {
        $app['config']->set('database.default', 'testing');
        $app['config']->set('your-package.key', 'test-value');
    }
}
```

## Combine Workbench with automated tests

Use Workbench for interactive checks and keep your `tests/` directory for repeatable automated assertions.

* Automation: regression safety in `tests/`
* Interactive verification: end-to-end behavior in `workbench/`

## Troubleshooting

```bash theme={null}
# Clear and do a full rebuild
composer clear && composer prepare && composer build

# Check package discovery
vendor/bin/testbench package:discover --ansi

# Inspect configuration
vendor/bin/testbench about

# List all routes
vendor/bin/testbench route:list
```

<AccordionGroup>
  <Accordion title="Workbench fails to build">
    Check `testbench.yaml` syntax and provider configuration. YAML indentation errors are a common cause.
  </Accordion>

  <Accordion title="Routes are not loading">
    Verify the route file paths and the WorkbenchServiceProvider registration. Confirm that `discovers.web` is set to `true` in `testbench.yaml`.
  </Accordion>

  <Accordion title="Database errors">
    Check that migration paths are correct. When using SQLite, make sure the `create-sqlite-db` build step is included.
  </Accordion>
</AccordionGroup>

## Related pages

<Columns cols={2}>
  <Card title="Testing Laravel packages with Orchestra Testbench" icon="flask-conical" href="/en/advanced/package-testing">
    Start with the package testing foundation first.
  </Card>

  <Card title="Package version compatibility management" icon="git-branch" href="/en/advanced/package-versioning">
    Learn version mapping and CI matrix strategy for Laravel and Testbench.
  </Card>
</Columns>

<Info>
  Source: [invokable/laravel-bluesky docs/workbench.md](https://github.com/invokable/laravel-bluesky/blob/main/docs/workbench.md), [Orchestra Testbench](https://github.com/orchestral/testbench)
</Info>


## Related topics

- [Testing Laravel packages with Orchestra Testbench](/en/advanced/package-testing.md)
- [Laravel Boost Custom Agent for GitHub Copilot CLI](/en/packages/laravel-boost-copilot-cli.md)
- [Laravel Package Skeleton — Official Package Starter Template](/en/blog/package-skeleton-introduction.md)
- [Laravel Package Development](/en/advanced/package-development.md)
- [Package Static Analysis (PHPStan / Larastan)](/en/advanced/package-static-analysis.md)
