PHPexp logo PHPexp

IDE autocompletion for Laravel magic

Published on

One of the things that makes Laravel great is all the magic. When you understand what's going on, the magic makes everything so much easier.

Unfortunately, your IDE won't understand most of the magic by default. This can be solved by using the Laravel IDE helper package . This package is a must-have for each Laravel project.

You can install the IDE helper package using composer:

composer require barryvdh/laravel-ide-helper --dev

After installation, you can generate helper files by running commands. I can't remember what these commands are, and realistically speaking, neither can you. A better solution is to add a script to your composer.json:

"scripts": {
    "ide": [
        "@php artisan ide-helper:generate",
        "@php artisan ide-helper:meta",
        "@php artisan ide-helper:models -N"
    ]
}

Now you can run composer ide to regenerate the helper files.

You shouldn't commit the helper files to version control. Add the following files to your (global) .gitignore file:

Regenerating the IDE helper files

IDE helper files aren't automatically updated. You have to regenerate them when you add new magic to your project. As a general rule, regenerate your IDE helpers after running database migrations and after making changes to your models.

IDE autocompletion for macros

The IDE helper package adds autocompletion for a lot of magic. But it does not work for Laravel macros. You can make your IDE understand macros by creating a custom IDE helper file.

Level up your Laravel deployments

If you aren't happy with your current deployment strategy for your Laravel apps, check out my premium deployment script.

Deploy with GitHub Actions Deploy with GitLab CI/CD