One of the best features of Laravel is how modular it is. Most of the framework is built
using libraries, or packages, that are well tested and widely used in other projects. By
using Composer for dependency management, we can easily include other packages and
seamlessly integrate them into our Laravel app.
For this recipe, we’ll be installing two popular packages into our app: Jeffrey Way’s Laravel 4
Generators and the Imagine image processing packages.
For this recipe, we need a standard installation of Laravel using Composer.
How to do it…
For this recipe, we will follow these steps:
1. Go to https://packagist.org/.
2. In the search box, search for way generator as shown in the following screenshot:
3. Click on the link for way/generators:
4. View the details at https://packagist.org/packages/way/generators and
take notice of the require line to get the package’s version. For our purposes, we’ll
use “way/generators”: “1.0.*”.
5. In our application’s root directory, open up the composer.json file and add in the
package to the require section so it looks like this:
6. Go back to http://packagist.org and perform a search for imagine as shown
in the following screenshot:
7. Click on the link to imagine/imagine and copy the require code for dev-master:
8. Go back to our composer.json file and update the require section to include the
imagine package . It should now look similar to the following code:
9. Open the command line, and in the root of our application, run the Composer update
php composer.phar update
10. Finally, we’ll add the Generator Service Provider, so open the app/config/app.php
file and in the providers array, add the following line:
How it works…
To get our package, we first go to packagist.org and search for the package we want. We
could also click on the Browse packages link. It will display a list of the most recent packages
as well as the most popular. After clicking on the package we want, we’ll be taken to the detail
page, which lists various links including the package’s repository and home page. We could
also click on the package’s maintainer link to see other packages they have released.
Underneath, we’ll see the various versions of the package. If we open that version’s detail
page, we’ll find the code we need to use for our composer.json file. We could either choose
to use a strict version number, add a wildcard to the version, or use dev-master, which will
install whatever is updated on the package’s master branch. For the Generators package,
we’ll only use Version 1.0, but allow any minor fixes to that version. For the imagine package,
we’ll use dev-master, so whatever is in their repository’s master branch will be downloaded,
regardless of version number.
We then run update on Composer and it will automatically download and install all of the
packages we chose. Finally, to use Generators in our app, we need to register the service
provider in our app’s config file.