Coding

How to configure PhpStorm for Laravel

If you develop web applications you certainly heard of Laravel, a PHP framework that uses HMVC architectural pattern, currently at version 5.1.4.

The best IDE currently available for Laravel is JetBrains PhpStorm, available for Windows, Mac OS X and Linux.

However, once installed, the IDE must be configured to be able to offer a series of facilities for Laravel, both as for PHP classes that for Blade templates engine syntax.

Let’s see in detail which are the steps to take:

1. Install PhpStorm (currently version 9)

The installation package can be downloaded at the following address:

https://www.jetbrains.com/phpstorm/download/

2. Install Composer

This tool can be downloaded at the following address:

https://getcomposer.org/download/

Write down Composer’s installation path, since it will be needed in the next steps.

3. Install Laravel IDE Helper

First of all, you must first configure Composer for your project. Open PhpStorm, create/open a project and click on the “File->Settings…” menu.

phpstorm_laravel_01

On Mac, the menu is “PhpStorm->Preferences…“.

phpstorm_laravel_01_mac

Select “Tools->Command Line Tool Support” and click on the green “+” button on top right of the window.

phpstorm_laravel_02

On Mac “+” button is the left bottom part of the window.

phpstorm_laravel_02_mac

At this point, after clicking “OK”, select the path of PHP interpreter (php.exe on Windows) and the Composer one (composer.phar), as shown, and click OK again.

phpstorm_laravel_03

Back to the settings screen, simply make sure that the Composer entry has a checkmark in the “Enabled” column and click “OK”.

phpstorm_laravel_04

The next step is to select the new “Tools->Composer->Add dependancy…” menu item (if it is disabled, first click on “Tools->Composer->Init Composer…“).

phpstorm_laravel_05

Then type “barryvdh/laravel-ide-helper” as search string and click on “Install”. In case of problems, select another version (eg 2.0.6) from the “Version to install” dropdown menu.

phpstorm_laravel_06

After adding this dependency, you’ll have to register “Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider” Service Provider in your application, adding the same line in the “/config/app.php” file of your project. phpstorm_laravel_07

As last step, launch the following command from your project’s directory command prompt:

php artisan ide-helper:generate

If everything is fine, the answer to the command will be “A new helper file was written to _ide_helper.php” and such file will be added to the root of your project.

4. Install Laravel plugin for PhpStorm

From the usual “File->Settings…” menu select “Plugins” and click on “Browse repositories…” at the bottom.

phpstorm_laravel_08

Search for “Laravel“, select “Laravel Plugin” and click on “Install Plugin” in the right window.

phpstorm_laravel_09

After installation is complete, click on “Restart PhpStorm”, then on “OK” and finally confirm with “Restart”.

phpstorm_laravel_10

phpstorm_laravel_11

After IDE is restarted, from the “File->Settings…” menu click on the new “Other Settings->Laravel Plugin” item and make sure “Enable plugin for this project” option is enabled.

phpstorm_laravel_12

5. Final check

At this point you have an autocomplete function for Laravel controllers, views, routes, configuration and translations, as shown in the following example.

phpstorm_laravel_13_it

In addition, a valid support is also provided for Blade templates:

phpstorm_laravel_14_it

Finally, you can navigate items using Ctrl+Click (CMD+Click on Mac OS X), or Go To Declaration (Ctrl+B on Windows, CMD+B on Mac OS X).

Now all you have to do is just practice with the new framework … enjoy!

Previous post

Linux: how to change default editor

Next post

Upgrade to Windows 10 without the upgrade icon

Fulvio Sicurezza

Fulvio Sicurezza

3 Comments

  1. Wednesday December 9th, 2015 at 03:59 PM — Reply

    I like to use Codelobster. It has special plug-in that supports Laravel much better: http://www.codelobster.com/laravel.html

  2. Thursday May 24th, 2018 at 10:02 PM — Reply

    Goodarticle

  3. Thursday November 15th, 2018 at 08:20 AM — Reply

    Good article…Keep sharing

Leave a reply

Your email address will not be published. Required fields are marked *