6

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

kalenjordan
  • 2,446
  • 1
  • 24
  • 38
  • Does this answer your question? [Eloquent ORM Code Hinting in PhpStorm](https://stackoverflow.com/questions/29439753/eloquent-orm-code-hinting-in-phpstorm) – miken32 Jan 11 '21 at 21:54

2 Answers2

8

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.

Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • I installed that one as well as another plugin that it referenced - still no luck - posted some detail as an update to my original question. Thanks again for your help. – kalenjordan Aug 23 '15 at 16:48
  • @kalenjordan - Yeah. Those plugins haven't been updated to 5.1 yet. – Joseph Silber Aug 23 '15 at 16:49
  • as a workaround, phpStorm has an option to **downgrade severity if __magic methods are present in class**. [Check my answer here](http://stackoverflow.com/a/35347256/1296104) – ruuter Feb 11 '16 at 18:39
2

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

Hugo Laf
  • 81
  • 3