Home >Backend Development >PHP Tutorial >How to Enable Code Hinting for Eloquent ORM in PhpStorm with Laravel IDE Helper?
Code Hinting for Eloquent ORM in PhpStorm with Laravel IDE Helper
Laravel's Eloquent ORM provides powerful methods for database interaction. However, these methods may not appear in code hinting in PhpStorm, limiting its effectiveness. To address this issue, Laravel IDE Helper offers an elegant solution: generated model PHPDocs.
To generate these PHPDocs, execute the following command:
php artisan ide-helper:models
This command creates a separate file, typically named _ide_helper.php, containing PHPDocs for all Eloquent models. The generated PHPDocs include information about the model's attributes, relationships, and available methods.
For example, the PHPDocs for a User model might look like this:
namespace App { /** * App\User * * @property integer $id * @property string $name * @property string $email * @property-read \Illuminate\Database\Eloquent\Collection|\App\Post[] $posts */ class User extends \Illuminate\Database\Eloquent\Model {} }
By including these PHPDocs in the model files, PhpStorm can accurately provide code hinting for Eloquent methods. To write directly to the model files instead of creating a separate file, use the following command:
php artisan ide-helper:models -W
This workaround generates the PHPDocs in the same file as the model definition.
Using Laravel IDE Helper with generated model PHPDocs ensures that code hinting in PhpStorm for Eloquent ORM methods is comprehensive and accurate, streamlining development and improving productivity.
The above is the detailed content of How to Enable Code Hinting for Eloquent ORM in PhpStorm with Laravel IDE Helper?. For more information, please follow other related articles on the PHP Chinese website!