Adding Composer Dependencies Into Laravel 5

2015-02-19 Laravel

Adding Composer dependencies into Laravel 5 is very easy but you have to remember about few things. To add third party packages into your Laravel, locate file called composer.json (root of your project) and paste the name of the package in require / require-dev section. In my case I had to add “illuminate/html”: “~5.0” package to use link_to_route method in my view.

Look for require-dev and at the end of this array add

"illuminate/html": "~5.0"

Now all you have to do is to update the Composer. Run

sudo composer update

so it will update your dependencies to the latest version according to composer.json.

If your Composer version is too old, you will get an exception quite similar to

Could not load package dragonrun1/phpspec in [UnexpectedValueException] Could not parse version constraint ^1.0.1: Invalid version string "^1.0.1"

Could not parse version constraint ^1.0.1: Invalid version string "^1.0.1"

That means you have to update Composer itself. Run

sudo composer self-update


sudo composer selfupdate

(both commands do exactly the same) and then

sudo composer update

You’re done.


  • Joginder Sharma

    When I run composer-self: command not found
    it give me error composer-self: command not found
    I think command should be like :- composer selfupdate

  • slick

    Hi Joginder, you’re absolutely right. Sorry for the typo. You can run “sudo composer self-update” of “sudo composer selfupdate”. Both do the same. In case of any doubts we can always type “composer | grep self” to see commands related to updating composer. Thanks for keeping an eye. :)

  • Rakesh Mistry

    Thank you

  • slick

    No worries Rakesh. Glad I could help. :)