Series: phpstorm
Part 3/3What is Laravel IDE Helper? 🚀#
An IDE (Integrated Development Environment) is a software that facilitates the software development process and brings together many development tools. Popular IDEs include Eclipse, Microsoft Visual Studio, Code Blocks, Dev-C++, NetBeans, and JetBrains products.
When developing Laravel projects, PHPStorm is frequently preferred as an IDE. However, PHPStorm may not automatically detect some model, class and route information. At this point, the Laravel IDE Helper package comes into play to improve the development experience.
If this package didn't exist, it would be necessary to manually add this information using PHPDoc. For more information on the subject, you can access explanations by Abdulkadir Dılo Sürücü here:
How to Install Laravel IDE Helper? 🛠️#
You can follow these steps to install the Laravel IDE Helper package in Laravel projects.
1. Install the Package#
Run the following command in your terminal or command line:
composer require --dev barryvdh/laravel-ide-helper
2. Enable Code Completion#
You can create the _ide_helper.php file in your project directory by running the following command:
php artisan ide-helper:generate
3. Publish Configuration File#
You can use the following command to publish the configuration:
php artisan vendor:publish --provider="Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider" --tag=config
4. Generate Documentation for Models 📌#
In some models, you may encounter a "function not found" warning. To solve this, you can use the following command:
php artisan ide-helper:models User
If your model files are in a different folder, you should specify the full path:
php artisan ide-helper:models Model\User
At the end of this process, a PHPDoc block like the following will be created at the beginning of model files like User.php:
/**
* App\User
*
* @property int $id
* @property string $name
* @property string $email
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @mixin \Eloquent
*/
5. Add Automatic Commands to Composer 🔄#
By adding the following scripts to your composer.json file, you can ensure that documentation files are automatically updated when the composer update command is executed:
"scripts": {
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"@php artisan ide-helper:generate",
"@php artisan ide-helper:meta"
]
}
Conclusion 🎯#
Laravel IDE Helper significantly improves the development experience by enhancing code completion and auto-suggestions in IDEs like PHPStorm. For more information, you can visit the Laravel IDE Helper Wiki page.
Also, be sure to check out my guide on Using PHP CS Fixer inside PhpStorm to automatically fix coding standards and boost code quality. 🚀

Comments