Search code examples
laravelphpstormlaravel-models

PhpStorm autocomplete with \Nwidart\Modules


The problem would be that I use PhpStorm IDE. The Laravel project is managed by nwidart/laravel-modules.

However, PhpStorm does not handle basic Laravel functions. For example: findorfail(), for own models:

Method 'findorfail' not found in \Modules\Companies\Models\Companies_adresses

example image

I did the following to enable autocomplete:

It is very confusing because it does not give tips correctly. It does not list database columns, etc... PHPDoc still came to mind, but I don't know how to get started!

You have no ideas? I feel completely lost :(


Solution

  • I set up the Laravel IDE Helper but I had to add the following into all my models...or you could add to a new Model class that you then extend to all of your models. Either way, this will get PHPStorm to read the facade methods like that correctly:

    use Illuminate\Database\Eloquent\Builder;
    use Illuminate\Database\Eloquent\Model;
    
    /**
     * Class Employee
     *
     * @mixin Builder
     */
    class Employee extends Model
    {
        // blah blah blah
    }
    
    

    Make sure the PHPDoc bumps up against your model. The key bit is the @mixin line which gives PHP Storm a connection to all the facade methods for your model. You will still need the IDE Helper as well. But with this PHPStorm will suggest as you type and allow you to control-click to view the method itself from elsewhere in your project.