orchestra/workbench
Orchestra Workbench is a Laravel package development companion that lets you preview, boot, and interact with your package in a lightweight app-like environment, making local testing and iteration faster and easier during development.
composer require --dev orchestra/workbench
workbench:install):
php artisan workbench:install
app/Workbench).php artisan workbench:devtool
http://workbench.test (or your configured URL).email@example.com / password./ in the Workbench to see your package’s routes/views rendered in a real Laravel context.php artisan your:package-command
config/testbench.php: Workbench/Testbench integration settings (e.g., TESTBENCH_USER_MODEL).app/Workbench/Providers/: Stubbed service providers for your package.database/factories/UserFactory.php: Customizable user factory for testing.routes/web.php: Your package’s routes, auto-loaded in Workbench.src/ files in your package.php artisan workbench:devtool --rebuild
/api routes.php artisan your:package:command --option=value
// In your Testbench test
$this->app->make(\Orchestra\Workbench\WorkbenchServiceProvider::class);
DatabaseSeeder, UserFactory, and routes/console.stub.php artisan vendor:publish --tag=workbench-stubs
WriteEnvironmentVariables action to inject .env vars:
use Orchestra\Workbench\Actions\WriteEnvironmentVariables;
WriteEnvironmentVariables::run([
'APP_URL' => 'http://workbench.test',
'DB_CONNECTION' => 'sqlite',
]);
ReplaceNamespaces action to ensure your package’s namespaces (e.g., Vendor\Package\) don’t clash with Workbench:
use Orchestra\Workbench\Actions\ReplaceNamespaces;
ReplaceNamespaces::run([
'Vendor\Package' => 'Workbench\Package',
]);
TESTBENCH_USER_MODEL in .env:
TESTBENCH_USER_MODEL=Workbench\Models\User
app/Workbench/Providers/AppServiceProvider.php) and modifying them.composer install --prefer-dist --no-interaction
php artisan workbench:install --quiet
php artisan workbench:devtool --no-interaction
DatabaseSeeder in CI:
php artisan migrate --env=testing
php artisan db:seed --class=DatabaseSeeder --env=testing
Stub Overwrites:
workbench:install replaces stub files. Back up custom stubs before updating Workbench.--keep flag or manually merge changes:
php artisan workbench:install --keep
Namespace Collisions:
Workbench\ namespace. If your package uses similar names (e.g., WorkbenchServiceProvider), conflicts arise.ReplaceNamespaces action or rename stubs post-install.Artisan Command Conflicts:
workbench:devtool). If your package has similarly named commands, they may override Workbench’s.Orchestra\Canvas\Core\Actions to namespace them.Database Migrations:
DatabaseSeeder runs after your package’s migrations. If your seeder depends on package tables, ensure proper ordering.// database/seeders/DatabaseSeeder.php
public function run()
{
$this->call([
\Vendor\Package\Database\Seeders\PackageSeeder::class,
]);
}
Environment Variables:
.env may override your package’s .env.testing. Test locally with:
php artisan workbench:devtool --env=testing
Workbench Not Loading?
WorkbenchServiceProvider is registered in config/app.php (added by workbench:install).routes/web.php for your package’s routes.Stub Files Missing?
php artisan vendor:publish --tag=workbench-stubs --force
User Factory Issues:
UserFactory may not match your package’s model. Override it:
php artisan vendor:publish --tag=workbench-factories
Custom Actions:
Extend Workbench’s actions (e.g., WriteEnvironmentVariables) by creating a service provider:
namespace Workbench\Providers;
use Orchestra\Workbench\Actions\WriteEnvironmentVariables;
class CustomActionsServiceProvider extends ServiceProvider
{
public function boot()
{
WriteEnvironmentVariables::macro('custom', function ($vars) {
// Custom logic
});
}
}
Dynamic Stub Generation:
Override stub paths in config/testbench.php:
'stubs' => [
'app/Providers/AppServiceProvider' => __DIR__.'/stubs/AppServiceProvider.stub',
],
Workbench as a Dependency: If your package requires Workbench for development (e.g., for a CLI tool), add it as a dev dependency and document the setup:
composer require --dev orchestra/workbench
workbench:devtool spins up a full Laravel instance. For CI, use --no-interaction and disable queues:
php artisan workbench:devtool --env=testing --no-interaction --queue=disabled
npm install && npm run dev
(Ensure node_modules are included in .gitignore for CI.)TESTBENCH_USER_MODEL:
Must be a fully qualified namespace (e.g., Workbench\Models\User). Relative paths (e.g., Models\User) fail silently.php artisan route:clear
php artisan queue:work --env=testing --once
How can I help you explore Laravel packages today?