Setting up PHPStorm to work with Laravel. Laravel is a wonderful framework that has a wide range of features and many implementations that make life easier for a programmer. However, the downside to this convenience is the difficulty in reading the code for the IDE. As a result, the IDE cannot parse the code properly and build full code completion. Therefore, in order for it to be convenient to work with Laravel in PHPStorm, it must be additionally configured.
This article will cover:
Specifying the path to the PHP interpreter, and selecting the current PHP version.
Specifying the path to the composer
Specifying the path to NodeJS
Installing the IDE plugin plugin
Setting up VueJs
Installing IDE-helper. Autocomplete methods
Artisan command completion
Presetting the IDE
Choosing PHP version and setting the path to the interpreter
PHP version and interpreter settings are located on the File | Settings | Languages & Frameworks | PHP
In the window that opens, 2 editable graphs will be available:
PHP Language Level – this is the PHP version by which the IDE will check the syntax of your written code. And if the syntax of the selected version does not match, an error will be highlighted right in the IDE.
CLI interpreter is the path to a PHP interpreter.
If you have not added interpreters before, then nothing will be available to you, therefore, now you need to add it by clicking, to the right of the interpreter selection, the search button (2)
After clicking on the (2) button, a menu will appear:
By clicking on (1) button, you will be offered a choice of 2 options:
From Docker, Vagrant, VM, Remote- in case you want to specify a remote interpreter (Docker, Vagrant)
Local Path to Interpreter – to specify the local version (as in my case)
And in PHP executable you need to register the path to PHP.
I use Laragon because my way of looking PATH_TO_LARAGON\bin\php…\php.exe,
In the case of OpenServer, the path will look something like PATH_TO_OS\modules\php\…\php.exe
In the case of Unix systems, like this: /usr/bin/php
Specifying the path to composer
The path to the composer is specified on the File | Settings | Languages & Frameworks | PHP | Composer
In this menu, you need to switch the option in composer.phar, and in this column (1) specify the path to the composer executable file.
And select the interpreter created in step earlier
For me, the path to the composer looks like this: E: \ laragon \ bin \ composer \ composer.phar
NodeJs, its package manager, NPM, will be a good helper in linking all the front-end libraries. Therefore, firstly, you need to specify the path to the NodeJs itself, and secondly, you need to configure everything so that the syntax of Vue templates is understandable for the IDE itself.
In the menu File | Settings | Languages & Frameworks | Node.js and NPM, similar to the previous points, you need to specify the path to nodeJs (after specifying it, NPM should automatically connect)
Now, there are some Laravel-related settings left to do.
Installing the Laravel plugin
Now you need to install the Laravel plugin in PHPStorm. Plugins are installed on the File | Settings | Plugins.
To search for a plugin, you need to enter laravel in the search bar
AND select the Laravel Plugin that interests us, which adds auto-completion in routes, views, configs.
When it’s installed, a new File | Settings | Languages & Frameworks | PHP | Laravel
On which, you need to check the Enable plugin for this project
Setting up VueJs
For VueJs, similar to Laravel, there is also a separate plugin. To install it, go to the File | Settings | Plugins find Vue and install
Connecting the necessary libraries, the last configuration steps
Now we already have a project to work with. However, there is still no autocomplete methods in routes, migrations, Eloquent, due to the special structure of the framework. To solve this problem, you need to download the laravel ide-helper library , which will generate additional meta-files for the IDE.
To install the IDE helper , use the composer ( Tools> Composer> Manage Dependencies )
And in the search bar, enter:barryvdh/laravel-ide-helper
After installing this library, you need to add to the config / app.php file , to the providers array :Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider:: class
‘providers’ => [
At this stage, you can already run ide-helper, and get the desired autocomplete effect. But, having done so at the moment, this library will take the default settings, in which the generation of Fluent methods is disabled. Therefore, first, copy the ide-helper.php config from the vendor / barryvdh / laravel-ide-helper / config folder to the local config folder.
And already in the local file, you need to change the value include_fluentto true.
‘include_fluent’ => true
Now it is enough to execute the command. After artisan ide-helper: generate
that, a new file will appear _ide_helper.php, which PHPStorm will successfully analyze, and we will get the desired auto-completion:
Artisan command completion
It is difficult to fill in all the artisan commands, and constantly being distracted by finding commands is not productive. Fortunately, PHPStorm provides the ability to create command autocompletion ( File | Settings | Tools | Command Line Tool Support ).
Artisan is a command based on the Symfony console, knowing this, add a command:
A menu will open in which you need to specify:
alias- what name the commands begin with (you can specify a and call a make: controller …
Path to PHP executable- our previously added to the interpreter
Path To Script- the path to the artisan project file
As a result, should be informed that the commands have been added:
And now, if you open the console: Tools> Run Commands
And all the commands that we start with artisan will be highlighted with a possible addition
In total, in this article, I discussed setting up laravel in phpstorm, installing plugins, it was also shown how to work with the Laravel IDE-helper, configure the composer and enable auto-completion of phpstorm artisan commands
Also, I recommend that you check out the article in which I show the process of installing and configuring the cool Monokai theme for PHPStorm, which you will definitely like, dear developer.