Detailed explanation of examples of developing Laravel applications with PHPStorm

黄舟
Release: 2023-03-15 21:06:01
Original
1961 people have browsed it

This article mainly introduces you to relevant information on how to use PHPStorm to develop Laravel applications. The article introduces it in great detail through sample code. It has certain reference learning value for everyone's study or work. Friends who need it can follow below. Let’s learn together.

Preface

I believe there are many PHP programmers using [laravel] to create their applications. [laravel] is a free and open source PHP web application framework. It is based on multiple Symfony components and provides a development framework, including authentication, routing, sessions, caching and other modules.

Last summer, we introduced support for Blade. Blade is Laravel's template language, artist-friendly, and a command-line tool for Laravel programmers that can work in PhpStorm. Using Laravel plugins and Laravel IDE helpers, we can further extend PhpStorm's support for Laravel applications. Let’s see how to do it!

Install Laravel IDE Assistant

Official Way

First confirm that Composer is available in our project, we can use Composer | Add dependency... right-click menu to install [Laravel 5 IDE Helper Generator] to our project. Search barryvdh/laravel-ide-helper, and Click Install to download and add it to the project.

[Translation] Self-service method

Because we are using it in the project, we use it in the project To add this function, add require-dev branch
laravel 4.* in composer.json, the version here should be filled in 1.*


"require-dev": {
  // ...
  "barryvdh/laravel-ide-helper": "2.*"
  // ...
},
Copy after login

and then Use the command composer update -vvv to update the package

Register the 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' service to our application, that is, write it to the provider in config/app.php, so that it will be in the artisan list There is an ide-helper command, run artisan ide-helper:generate, PhpStorm will have code completion function, and have Laravel syntax highlighting.

Laravel plug-in in PhpStorm

##In order to further enhance our Laravel experience, we can also install the Laravel plug-in. In Settings (Preferences) | Plugins, click the Browse repositories… button and search for Laravel. The Install plugin button will Download and install the plugin into the IDE.

Restart the IDE and enable the plugin (Settings (Preferences) | Other Settings | Laravel Plugin | Enable Plugin for this Project). PhpStorm knows about Laravel What the interface does, and provides code completion for (controllers, views, routes, configuration, translations, etc.)!

Of course it’s not just code completion, use Ctrl+Click (CMD+Click Mac OS X) or Go To Declaration (Ctrl+B / CMD+B), PhpStorm will navigate there, such as the declaration of the configuration item.


Regarding using Blade templates, Laravel plug-ins can also improve the experience, such as: automatic completion of @section instructions.


Want to know more? Check out our Laravel Tutorial, which covers everything PhpStorm has to offer for Laravel development, including code auto-completion, navigation, automatic code inspection, command line tool support, debugging and unit testing!

You can also add commands to the post-update-cmd of composer.json to ensure that the helper will be updated every time it is updated, as follows:


"post-update-cmd": [
  "php artisan clear-compiled",
  "php artisan ide-helper:generate",
  "php artisan optimize"
 ],
Copy after login

In addition, if your model is extended Eloquent, this plug-in can also add phpDoc to the model in the project and directly display the field names for easy reading. The usage


php artisan ide-helper:models User
Copy after login

needs to be modified. composer.json, add


"require-dev": {  
  "doctrine/dbal": "~2.3"
},
Copy after login

Summary in the require-dev section

The above is the detailed content of Detailed explanation of examples of developing Laravel applications with PHPStorm. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!