Search code examples
laravellumen

Why isn't my IDE auto-completing the findOrFail method?


So I've created a Message model:

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Message extends Model
{
    public function getName()
    {
        return $this->name;
    }

    public function setSortOrder($sortOrder)
    {
        $this->sort_order = $sortOrder;
        return $this;
    }
}

And it seems to be working just fine - I've created some columns using migrations, loaded, and saved the model.

But my IDE (PHP Storm) doesn't seem to be recognizing some of the methods on the model - namely findOrFail. It does autocomplete findOrNew though.

Wondering whether something in lumen is pointing to a more stripped-down version of the base model class. But again the weird thing is that this method is working just fine when I run it - it's just the IDE that doesn't seem to be aware of it.

enter image description here

Update

Thanks @joseph-silber for the tip about the Laravel plugin for PHPStorm. I just found that and installed it. I'm not seeing any settings immediately that would enable docblock generation in there.

enter image description here

In the notes for the Laravel plugin page, it mentions the "Laravel IDE Helper Generator". I did a search for that and found this Laravel plugin by Haehnchen which I installed.

This added the ide-helper:models option to my artisan command list as well as a few others. I ran that and it did generate some methods in the docblock but not all of them.

enter image description here


Solution

  • Because the model class doesn't have a findOrFail method.

    It's only available on the builder, which gets called from the model's catch-all __call method.


    If you want PHP Storm to help you out there, try the Laravel plugin to generate the IDE classes.