Eloquent is full of magic, so PhpStorm needs some helper code to understand it. There are 2 ways to do it:
ide-helper:models
artisan command)Generate Eloquent Helper Code command is available in the Laravel main menu item:
It also can be called by quick key combination (Shift-Cmd(Ctrl)-.) and helper code will be quickly generated without any dialog windows. However, first call will ask you to configure the Eloquent helper code generation:
User::with_count('posts')->first()->posts_count
. You can add these properties to the helper code.After generating a helper code Laravel Idea starts to complete fields and relations almost everywhere:
Even in complex cases, it understands that here it should complete Post class fields:
Relations chain is also not a problem:
Fields inside class:
JSON resource generation is accessible from the main Code generation menu or in the Generate menu in the Eloquent class (Alt-Ins or Command(Ctrl)-N). It uses fields and relations information to generate full JSON resource for this class:
Database factory generation is accessible from the main Code generation menu or in the Generate menu in the Eloquent class (Alt-Insert or Command(Ctrl)-N). It uses fields and relations information to generate full database factory for this class:
Laravel Idea hints the type of factory()->create()
calls:
Multiple create also supported: