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.
On Mac, the menu is “PhpStorm->Preferences…“.
Select “Tools->Command Line Tool Support” and click on the green “+” button on top right of the window.
On Mac “+” button is the left bottom part of the window.
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.
Back to the settings screen, simply make sure that the Composer entry has a checkmark in the “Enabled” column and click “OK”.
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…“).
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.
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.
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.
Search for “Laravel“, select “Laravel Plugin” and click on “Install Plugin” in the right window.
After installation is complete, click on “Restart PhpStorm”, then on “OK” and finally confirm with “Restart”.
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.
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.
In addition, a valid support is also provided for Blade templates:
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!
3 Comments
I like to use Codelobster. It has special plug-in that supports Laravel much better: http://www.codelobster.com/laravel.html
Goodarticle
Good article…Keep sharing