Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

laravel

lumen

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

like image 451
kalenjordan Avatar asked Aug 23 '15 16:08

kalenjordan


2 Answers

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.

like image 151
Joseph Silber Avatar answered Oct 28 '22 23:10

Joseph Silber


Use query() method and you have IDE autocomplete there User::query()->findOrFail(...) that is equivalent to User::findOrFail(...) but with autocomplete for Laravel methods in st-bnv

like image 21
Hugo Laf Avatar answered Oct 28 '22 21:10

Hugo Laf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!