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

Laravel 5.3 正式发布了,Laravel 5.3 在 5.2 基础上进行了优化。

[目录]

新特性包括以下:

  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
  • 消息通知系统 Laravel
    Notifications;

  • 事件广播系统 Laravel
    Echo;

  • Laravel Passport 快速 OAuth2
    服务器的扩展包;

  • Laravel Scout
    全文搜索引擎;

  • Laravel Elixir 开始支持 Webpack;

  • 邮件操作 Laravel Mailable;

  • web 和 api 的路由分离;

  • 基于闭包的控制台命令;

  • 上传文件存储的帮助函数;

  • 支持 POPO 和单动作控制;

  • 优化默认前端脚手架,等。

 

官方发行说明:

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.

澳门新葡亰8455下载app 1

  • Source
    code (zip)

  • Source
    code (tar.gz)

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.

澳门新葡亰8455下载app 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:

澳门新葡亰8455下载app 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.

澳门新葡亰8455下载app 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 澳门新葡亰8455下载app,Browse
repositories…
button and search for Laravel. Next, we can use the
Install plugin button or the context menu to proceed with plugin
installation.

澳门新葡亰8455下载app 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.

澳门新葡亰8455下载app 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:

澳门新葡亰8455下载app 7
澳门新葡亰8455下载app 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.

澳门新葡亰8455下载app 9

网站地图xml地图