Create a Laravel 5 package with Laravel 4 illuminate/workbench

At Yourwebhoster.eu we work with the Laravel framework for our internal systems. The framework provides us basic functions and a MVC structure making development much easier. We can extend the framework with packages of third party developers allowing us to develop even faster. For example there are plenty of packages to connect our systems with Twitter (still a todo thing).

Like most Laravel developers we have written our own packages for Laravel 4 with the help of the Laravel 4 workbench command. Taylor Otwell has dropped the Workbench command because he wants the packages to be a PHP-wide solution without requiring the Laravel framework. Although we understand what Taylor wants it makes the work for us a bit more difficult: our packages are Laravel-only and we just like the ease of workbench.

Luckily it is easy to restore the workbench feature in Laravel 5. After comparing the code and dependencies of Laravel 4 and 5 I have found the following solution:

1. Run the following commands to download the required packages:

composer require "illuminate/workbench:dev-master"
composer update

2. Tell Laravel that workbench is back. Open config/app.php (or your environment file) and add the following line to providers:

'IlluminateWorkbenchWorkbenchServiceProvider',

3. Open bootstrap/autoload.php and add the following code after the line with “require __DIR__.’/../vendor/autoload.php’;”:

/*
|--------------------------------------------------------------------------
| Register The Workbench Loaders
|--------------------------------------------------------------------------
|
| The Laravel workbench provides a convenient place to develop packages
| when working locally. However we will need to load in the Composer
| auto-load files for the packages so that these can be used here.
|
*/
if (is_dir($workbench = __DIR__.'/../workbench'))
{
IlluminateWorkbenchStarter::start($workbench);
}

This tells Laravel to include the workbench files. Presto! You can use the workbench cli command again.

Note: There is a reason why Taylor dropped the workbench and it is likely workbench will stop working in the future. In the mean time this may help you if you are exploring Laravel 5.