Laravel 5 Package Development: Setup

As of this writing, Laravel 5 is very close to having an alpha release. Consequently many developers are now scrambling to get their Laravel 4 pacakges working with Laravel 5. This is the start of a series of posts about my experience making that upgrade for one of my packages.

One major difference with Laravel 5 is the deprecation of the Workbench, which means we will need to use a different tactic for setting up our package development environment. Some people may scoff at this, but I actually think it will prove to be an excellent decision in the long run. Here I will outline three strategies for package development setup - each has pros and cons; you will need to experiment to find what suits you best.


First we will need a new installation of Laravel 5 - see here for instructions. For the sake of this tutorial, let us assume that this installation is located at /home/laravel5.

Secondly, we need a separate directory to hold our package repository. Create a new folder and clone your git repository into that folder. For the sake of this tutorial, let us assume that the package repository is located at /home/sentinel-dev.

Method 1: Local VCS Repository

Composer allows us to load dependencies from local git repostitores. As a bonus, local packages are given priority over pacakges pulled in from, so we can use the same naming convention from our extant package. My package is called rydurham\sentinel; to have composer pull in the develop branch from my local folder I put this in my new laravel 5 application's composer.json file:

   // ...
   "repositories": [
         "type": "vcs",
         "url": "/home/sentinel-dev"
   // ...
   "require": {
      // ...
      "rydurham/sentinel": "dev-develop"

We can now run composer update and composer will pull in the package from the /home/sentinel-dev folder the same way it would from github. The downside to this method is that we have to commit changes to our sentinel repo and then run composer update each time we want to test new changes to Sentinel in our Laravel 5 application.

Method 2: Symbolic Links

For me, having to run composer update each time I tweak some code proved to be quite tedious and it slowed down my development process quite a bit. To solve that problem, we can use a symbolic link between the package directory and the Laravel 5 vendor directory. This method will build on Method 1.

Note: If you are running Vagrant on Windows, as I am, you may have trouble getting Vagrant to play nicely with symbolic links. There is a workaround which I will summarize briefly: First add this code your homestead Vagrantfile:

config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]

Make sure you put it within the Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| block - see here. Secondly, you need to run VirtualBox as an administrator. This can be done by right clicking on your console application and choosing the "Run as Administrator" option. You will need to re-provision your machine as an administrator once these steps have been taken.

Now perform all the steps required in method 1 and then delete your package folder from the vendor directory:

$ rm -rf /home/laravel5/vendor/rydurham

Assuming you are having no trouble with sym-links, you can now run this from your command line:

$ ln -s /home/sentinel-dev /home/laravel5/vendor/rydurham/sentinel

Now run composer dump-autoload and you are good to go. The downside to this method is that running a composer update in your Laravel 5 application will most likely remove the symbolic link - you will need to re-create it.

Method 3: franzl/studio

Franz Liedke mentioned in the comments to this post that he has created a tool to help simplify the package development process. To use it, first start with a fresh laravel installation and then install the franzl/studio package within that application. (You could also install it globally if you would prefer.)

$ composer require --dev franzl/studio

Once installed, you can create a new package folder using the create method:

$ vendor/bin/studio create rydurham/sentinel

You will be prompted for various details about your package, after which a new directory will be created to house your package's files and the autoloading for that folder will be taken care of automatically - no need to adjust the composer.json file in your parent application.

The Studio tool also supports the ability to import existing packages, making it that much better!


comments powered by Disqus