Laravel is a free, open source PHP web application framework. It is built on top of several Symfony components, and makes common tasks such as authentication, routing, sessions and caching much easier to implement.
Before you start
Before you start working with Laravel, make sure that Laravel plugin is installed and enabled.
Additionally, make sure Composer is installed on your machine and initialized in the current project as described in Composer Dependency Manager.
Perform initial configuration
Add Laravel IDE helper as a
ServiceProviderinto the application. In the config/app.php file, add
providerselement:return array( // ... 'providers' => array( // ... // Laravel IDE helper 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', ), // ... );
The Laravel IDE Helper may have to be run after changing or adding services, controllers, models and views. Alternatively, set up File Watchers in PhpStorm to automatically regenerate this file when, for example, composer.json is updated.
You can also install the Laravel generators Composer package to add various Laravel generators for models, views, controllers, and much more.
The Laravel plugin provides code completion and navigation for various Laravel components: controllers, routes, views, configuration, services, and translations. You can also use Laravel-specific live templates for generating various Laravel entities.
Reference a controller when using the
Routefacade's various functions:
Reference a Blade template (or view) when using the
Reference various keys that are defined in our application's settings when using the
Complete various translation keys when using the
Navigate to the controller's declaration:
Navigate to a Blade template (or view) declaration:
Navigate to the declaration of a configuration entry or a service:
Navigate to the declaration of a translation key:
Generating code with Live Templates
PhpStorm provides numerous code generation facilities. After downloading and installing the PhpStorm Laravel Live Templates, you can extend the standard live templates set with Laravel-specific live templates, such as:
Input and Request snippets
Route snippets and generation
View, Response and Redirect templates
Building schema (includes column types)
Form and session snippets
Snippets calling various helpers
Blade templates support
Before you start, make sure the Blade Support plugin is installed and enabled. The plugin is activated by default. If the plugin is disabled, enable it on the Plugins page as described in Managing plugins.
Besides syntax highlighting, PhpStorm provides several other Blade-specific features.
Code completion for braces and directives
@foreach directives are used, variable introduction with code completion is available inside the construct's body.
While working on a Blade template, you can open a section using the
@section directive. PhpStorm provides code completion Ctrl+Space for all known sections' names in the project.
PhpStorm provides the code inspection that detects the sections that are not closed using the
The Laravel plugin also adds a marker to the editor gutter, which lets you navigate to the parent section.
Code completion and navigation for extends and includes
Blade templates are often composed of various includes of small reusable blocks, which are in turn other templates. You can also extend templates and provide content for additional sections. PhpStorm and the Laravel plugin provide completion for template names in both the
@extends and the
@include directives. Completion suggestions include template directory names as well as full template names.
Debugging Blade templates
You can debug Blade templates using the same techniques as for regular PHP files.
Enable Blade debugging
In the Cache path field, provide the path to the Blade compiled templates cache folder. Type the path manually or click and select the relevant folder in the dialog that opens.
Start a debugging session
Configuring Blade templates
Add, modify, or remove Blade directives
In PhpStorm, Blade directives are managed on the Directives tab of the Blade Page. The tab lists all the currently available Blade directives, for those that have parameters, the prefixes and suffixes are also shown. When you start, the list contains only predefined directives. You can edit these directives as well as create custom ones.
On the Blade page that opens, switch to the Directives tab, which shows a list of all currently available directives.
To define a new directive, click and specify the directive's name in the Name field.
If the new directives requires a prefix and a suffix, select the Has parameter checkbox and type the prefix and suffix to use in the Prefix and Suffix fields respectively. PhpStorm will automatically enclose the prefix and suffix in opening and closing brackets and quotes and add a colon separator
:so the parameters will look as follows: ("<prefix>:<suffix>").
To edit an existing directive, select it in the list and change the values in the fields below.
To remove a directive from the list, select it and click .
Configure Blade delimiters
PhpStorm recognizes Blade templates and provides error highlighting and code completion for them based on the delimiters you specify.
The fields are filled in with the default values in compliance with Blade Templates 5.8. If you are using an earlier version, you can specify the relevant custom delimiters and PhpStorm will provide coding assistance according to the new rules.
Using the artisan command line tool from PhpStorm
Configure artisan as a command line tool
Click on the toolbar.
In the Command Line Tools dialog, choose Tool based on Symfony Console from the list, and specify its visibility level (Project or Global).
When you click OK, the tool settings dialog opens.
Specify the tool alias, provide the path to artisan and the PHP executable.
Click OK to apply changes and return to the Command Line Tool Support page. Optionally, click to edit the tool properties, or to customize the commands set. See Customizing a tool for details.
Run Artisan commands
From the main menu, chooseor press Ctrl twice.
In the Run Anything window that opens, type the call of the command in the
The command execution result is displayed in the Run Tool Window.
Terminate a command
Click on the Run Tool Window toolbar.
Debug Artisan commands
Laravel commands are defined in controller classes that extend
Command. To debug a command, it is crucial that you debug the command itself, and not the controller class file it is defined in. Otherwise, the Laravel bootstrapping process will be skipped, and the execution will fail.
In the controller class corresponding to the selected command, click the editor gutter at a code line where you want to set a breakpoint.
Create a run/debug configuration that will run the artisan tool with the selected command. In the main menu, select , then click and choose PHP Script from the list.
In the Run/Debug Configuration: PHP Script dialog, provide the run/debug configuration parameters.
In the File field, provide the path to the artisan executable file.
In the Arguments field, type the actual command and its arguments, such as
On the PhpStorm toolbar, select the created run/debug configuration and click . The command execution will stop at the specified breakpoint.