PhpStorm 2019.1 Help


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.

Laravel support is provided by means of the Laravel plugin and the Laravel IDE helper.

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

  1. Install Laravel IDE helper generator with Composer. To do this, open Tools | Composer | Manage Dependencies from the main menu and install the barryvdh/laravel-ide-helper package. Refer to Installing a specific package for details.

  2. Add Laravel IDE helper as a ServiceProvider into the application. In the app/config/app.php file, add Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class under the providers element:

    return array( // ... 'providers' => array( // ... // Laravel IDE helper 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', ), // ... );
  3. Enable command line tool support for artisan:

    • In the Settings/Preferences dialog (Ctrl+Alt+S), add a new command line tool under Tools | Command Line Tool Support.

    • Set the tool type to Tool based on Symfony Console.

    • Provide the path to artisan:

      the artisan command-line tool settings

    You can now use artisan from within PhpStorm.

  4. Open the Command Line Tools Console Tool Window by either selecting Tools | Run Command... from the main menu or pressing Ctrl+Shift+X.

    Run the artisan ide-helper:generate command to generate the required PHPDoc information.

    the artisan generate command

    PhpStorm and the Laravel plugin will use this information to provide code completion and navigation.

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.

Coding assistance

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.

Code completion

In the editor, press Ctrl+Space to invoke code completion and do any of the following:

  • Reference a controller when using the Redirect and Route facade's various functions:

    Laravel controller completion
  • Reference a Blade template (or view) when using the View facade:

    Laravel view completion
  • Reference various keys that are defined in our application's settings when using the Configuration facade:

    Laravel configuration key completion
  • Complete various translation keys when using the Lang and calling Lang::get():

    Laravel translation key completion

Code navigation

To navigate to the declaration of an item, position the caret at its usage and press Ctrl+B. Alternatively, Ctrl+Click (for Windows and Linux) or ⌘+Click (for macOS) the usage.

  • Navigate to the controller's declaration:

    Navigate to Laravel controller declaration
  • Navigate to a Blade template (or view) declaration:

    Navigate to Blade template declaration
  • Navigate to the declaration of a configuration entry or a service:

    Navigate to configuration entry or service declaration
  • Navigate to the declaration of a translation key:

    Navigate to translation key declaration

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:

  • Blade directives

  • Input and Request snippets

  • Cookie snippets

  • Route snippets and generation

  • View, Response and Redirect templates

  • Building schema (includes column types)

  • Cache

  • 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.

PhpStorm provides full support of the Laravel Blade template engine up to version 5.8. It highlights various Blade syntax constructs, as well as any HTML, JavaScript and CSS code inside the templates.

Besides syntax highlighting, PhpStorm provides several other Blade-specific features.

Code completion for braces and directives

PhpStorm's editor provides code completion both for standard and custom Blade directives, which can be defined In the Settings/Preferences dialog (Ctrl+Alt+S) under Languages & Frameworks | PHP | Blade.

Laravel Blade directive completion

When @for or @foreach directives are used, variable introduction with code completion is available inside the construct's body.

Laravel Blade variable introduction completion

Sections support

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.

Laravel Blade section completion

PhpStorm provides the code inspection that detects the sections that are not closed using the @stop directive.

Laravel Blade closed section inspection

To navigate to the declaration of a section, position the caret at its usage and press Ctrl+B. Alternatively, Ctrl+Click (for Windows and Linux) or ⌘+Click (for macOS) the usage.

The Laravel plugin also adds a marker to the editor gutter, which lets you navigate to the parent section.

Navigate to the parent section via the gutter icon

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.

Laravel Blade @extends directive completion

To navigate to the declaration of a template, position the caret at its usage and press Ctrl+B. Alternatively, Ctrl+Click (for Windows and Linux) or ⌘+Click (for macOS) the usage.

Debugging Blade templates

You can debug Blade templates using the same techniques as for regular PHP files.

Enable Blade debugging

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Languages & Frameworks | PHP | Debug | Templates and expand the Blade Debug area.

  2. In the Cache path field, provide the path to the Blade compiled templates cache folder. Type the path manually or click the Browse button and select the relevant folder in the dialog that opens.

Start a debugging session

  • Start a debugging session as described in the Ultimate debugging guide. The easiest and recommended approach is to use Zero-Configuration Debugging:

    1. Choose and install the browser extension suitable for your browser.

    2. On the PhpStorm toolbar, toggle the Start Listening for PHP Debug Connections button to start listening for incoming PHP debug connections, or choose Run | Start Listening for PHP Debug Connections from the main menu.

    3. Set a breakpoint in your code.

    4. Start the debugging session in the browser using the installed browser extension.

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.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Languages & Frameworks | PHP | Blade.

  2. 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 the Add button 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 restore the original definition, click the Reset to defaults button.

    • To remove a directive from the list, select it and click the Remove button.

Configure Blade delimiters

PhpStorm recognizes Blade templates and provides error highlighting and code completion for them based on the delimiters you specify.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Languages & Frameworks | PHP | Blade.

  2. On the Blade page that opens, switch to the Text Tags. The fields in the tab show the opening and closing characters for raw tags, content tags, and escaped tags.

  3. 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.

Last modified: 26 July 2019

See Also