>

美洲杯在线投注_2019美洲杯外围投注[投注官网]

热门关键词: 美洲杯在线投注,2019美洲杯外围投注[投注官网]

优雅的使用 PhpStorm 来开发 Laravel 项目

- 编辑:美洲杯在线投注 -

优雅的使用 PhpStorm 来开发 Laravel 项目

Laravel & PHPStorm – the best of the two worlds. Laravel is the most popular PHP web framework today. PHPStorm is the best PHP IDE that money can buy. What’s sad is that there is still no built in support for Laravel in PHPStorm. I created an issue on YouTrack (Jetbrain’s issue tracker) a long time ago which has received quite a good number of votes by today. I do hope Laravel support will come soon on the IDE. Meanwhile, there are workarounds to get things done smoothly.

[目录]

Auto Completion

Thanks to the massive class aliasing (& use of Facade) in the framework core, PHPStorm can’t provide true autocompletion for Laravel by default. But there are excellent packages likeLaravel IDE Helperwhich can generate phpdocs from the framework source. It generates a file which the IDE can parse and use the generated codes to provide autocompletion.

Installation and usage is simple. First modify your composer.json to include it in the require section:

{// [snip]"require": {"laravel/framework": "4.1.*","barryvdh/laravel-ide-helper": "dev-master"}// [snip]}
{    // [snip]

    "require":{

        "laravel/framework":"4.1.*",

        "barryvdh/laravel-ide-helper":"dev-master"

    }    // [snip]}

Run composer update:

composer update
composerupdate

The package should be installed if everything goes right. Now, you need to make sure the package is loaded in Laravel (so that artisan can execute the commands it provides). Add this to the providers array under app/config.php – ‘Barryvdh/LaravelIdeHelper/IdeHelperServiceProvider’. It should look like:

'providers' => array(// [snip]'Illuminate/Workbench/WorkbenchServiceProvider','Barryvdh/LaravelIdeHelper/IdeHelperServiceProvider',),

'providers'=>array(

        // [snip]

        'Illuminate/Workbench/WorkbenchServiceProvider',

        'Barryvdh/LaravelIdeHelper/IdeHelperServiceProvider',

    ),

Now you can do this in command line:

php artisan ide-helper:generate

phpartisanide-helper:generate

The command should generate a file named “_ide_helper.php” with the necessary codes. You might want to recreate the code cache from “File” > “Invalidate Caches / Restart”. When the IDE restarts, you should get code completion for most of the Laravel code.

  1. Prerequisites plugin installation and configuration
    1. 1 Ensure Composer is initialized
    2. 2 Install the Laravel IDE Helper
    3. 3 Generate the PHPDoc Helper File using Artisan
    4. 4 Install and enable the Laravel Plugin
  2. Laravel Framework Support in PhpStorm
    1. Code Completion and Navigation for Controllers and Routes
    2. Code Completion and Navigation for Views
    3. Code Completion and Navigation for Configuration and Services
    4. Code Completion and Navigation for Translations
    5. Automatic PSR-4 Namespacing
  3. Blade Template Support in PhpStorm
    1. Code Completion for Braces and Directives
    2. Sections Support
    3. Code Completion and Navigation for Extends and Includes
  4. Generating Code with Live Templates
  5. Command Line Tool Support for Artisan and Composer
  6. Debugging Laravel Applications with PhpStorm
  7. Laravel Unit Testing with PhpStorm
  8. Database Support in PhpStorm

Blade Syntax

This one could be a bit tricky. But if you have installed Textmate bundles into Jetbrains IDEs, it’s actually simpler.

(1) Download the textmate bundle here – https://github.com/outofcontrol/Blade.tmbundle. If you download the zip, uncompress it to somewhere on your harddisk.

(2) From PHPStorm’s Settings window, go to TextMate Bundles. Add the bundle and apply the changes.

(3) Go to “File Types” settings. Select “File types supported via textmate bundles”. Add “*.blade.php” to that list. Apply the changes. Now try and open a blade file. It should work.

(4) Additionally, if there’s horrible color scheme on blade files, go back to “Settings” > “TextMate Bundles”, assign the color schemes to Darcula. (In my case, I switched all to Dracula under the “TextMate Color Scheme” column. If you click an item under that column, you should get a pop up to select.)

Now the blade syntax should work fine with nice color scheme.


 

Laravel is a free, open source PHP web application framework. It is built on top of severalSymfony components, and provides a development framework that makes common tasks such as authentication, routing, sessions and caching much easier to implement.

In this tutorial, we'll see how we can develop Laravel applications using PhpStorm taking advantage of the Laravel plugin for PhpStorm and the Laravel IDE helper. Make sure to explore the generic PhpStorm tutorials and Laracast's PhpStorm tutorials to learn more about Laravel and PHP development using PhpStorm.

 

Prerequisites (plugin installation and configuration)

PhpStorm comes with code completion, navigation, automatic inspections, refactoring, ... for PHP. It also provides support for Laravel's template engine, Blade. Using the Laravel plugin and the Laravel IDE helper, we can extend PhpStorm's support for Laravel applications. Let's install them into our project.

There's a bit of setup work initially, but this is only needed once. It will make sure we get full Laravel support in PhpStorm, including code completion, navigation, Composer support, Artisan command-line support and additional Blade syntax support.

1. Ensure Composer is initialized

One thing we want to make sure beforehand is that Composer is initialized and configured in PhpStorm. After opening a Laravel project, select the root node in the project tool window and use the Composer | Init composer... context menu. PhpStorm can download composer.phar if needed.

图片 1

2. Install the Laravel IDE Helper

Once Composer is available for use in our project, we can install the Laravel IDE helper into our project. We can use theComposer | Add dependency... context menu and search for barryvdh/laravel-ide-helper. Click Install to download the package and add it to our project.

图片 2

Once installed, we have to add the Laravel IDE helper as a ServiceProvider into our application. In the app/config/app.phpfile, add 'BarryvdhLaravelIdeHelperIdeHelperServiceProvider' under the providers element:

<?php
return array(
    // ...

    'providers' => array(
        // ...

        'BarryvdhLaravelIdeHelperIdeHelperServiceProvider', // Laravel IDE helper

    ),

    // ...
);

Laracasts also has a video tutorial available on enabling PhpStorm support for Laravel Facades using the Laravel IDE Helper.

3. Generate the PHPDoc Helper File using Artisan

After installing the Laravel IDE Helper, we can use artisan to generate a PHPDoc helper file that PhpStorm and the Laravel plugin will use to provide code completion and navigation.

The easiest way to do this is by enabling command line tool support for artisan. From the settings, add a new command line tool under Tools | Command Line Tool Support. The tool type is a Tool based on Symfony Console. Next, provide the path to artisan:

图片 3

Once saved, we can use artisan from within the IDE. The Tools | Run Command... menu (Ctrl Shift X or CMD Shift Xon Mac OS X) provides completion for all artisan commands that are available. Run the artisan ide-helper:generate command to generate the required PHPDoc information.

图片 4

The Laravel IDE Helper may have to be run after changing or adding services, controllers, models and views. TheLaravel IDE Helper GitHub page provides additional tips on running it, for example, after performing an install or update of Composer dependencies.

Another options is using File Watchers in PhpStorm to automatically regenerate this file when, for example,composer.json is updated.

4. Install and enable the Laravel Plugin

Under Settings (Preferences) | Plugins, click the Browse repositories... button and search for Laravel. Next, we can use the Install plugin button or the context menu to proceed with plugin installation.

图片 5

Restart the IDE to complete the installation of the plugins. Next, we will have to enable the Laravel Plugin in our project. We can do this from Settings (Preferences) | Other Settings | Laravel Plugin | Enable Plugin for this Project. We'll have to restart the IDE once more to load the plugin's additional features for Laravel.

图片 6

In case of any problems with the completion and navigation support provided by this plugins, select File | Invalidate Caches / Restart to reindex your project. Running artisan clear-compiled and artisan ide-helper:generate may also be required.

Laravel Framework Support in PhpStorm

Let's explore the Laravel plugin's features for working in PHP code.

Code Completion and Navigation for Controllers and Routes

When referencing a controller, we can use code completion by pressing Ctrl Space (CMD Space on Mac OS X) and select the controller from the list that pops up. This works when using the Redirect and Route facade's various functions:

图片 7
图片 8

We can also navigate to the controller using Ctrl Click (CMD Click on Mac OS X) or Go To Declaration (Ctrl B /CMD B). Simply hovering the mouse with the Ctrl or CMD key pressed will show additional details.

图片 9

本文由计算机教程发布,转载请注明来源:优雅的使用 PhpStorm 来开发 Laravel 项目