Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kevineger's avatar

Problems with laravel-ide-helper

I am going through the Laravel 5 Fundamentals Laracasts video set but am having some difficulties with Facades in my IDE (Phpstorm 8). I have a model which uses the Eloquent facade use Illuminate\Database\Eloquent\Model;

I have required the laravel-ide-helper composer require barryvdh/laravel-ide-helper, added the service provider to the providers array 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',, regenerated the docs and restarted my IDE, but with no success.

I have a Model decleration in my Controller $article = Article::findOrFail($id); but the findOrFail method is highlighted and flagged as Method 'findOrFail' not found in class App\Article.

I am new to Laravel and the concept of Facades but am lost and have been unable to find an existing answer for my problem.

0 likes
8 replies
mstnorris's avatar

@kevineger findOrFail() isn't highlighted by PhpStorm as it is a magic method. Don't worry as it will still work :)

Just for reference I've included the method where it is within the Builder class.

Eloquent/Builder.php class

/**
 * Find a model by its primary key or throw an exception.
 *
 * @param  mixed  $id
 * @param  array  $columns
 * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection
 *
 * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
 */
public function findOrFail($id, $columns = array('*'))
{
    $result = $this->find($id, $columns);

    if (is_array($id))
    {
        if (count($result) == count(array_unique($id))) return $result;
    }
    elseif ( ! is_null($result))
    {
        return $result;
    }

    throw (new ModelNotFoundException)->setModel(get_class($this->model));
}

The file is located in vendor\laravel\framework\scr\Illuminate\Database\Eloquent\Builder.php

kajetons's avatar

You're saying that you are using facades but at the same use the actual model class here use Illuminate\Database\Eloquent\Model;. So which one is it?

To be fair, there is really no point in using facades in Laravel, especially since version 5 came out. Almost everything can be accomplished with proper dependency injection and / or new helper methods. Makes the end result much clearer, IMO.

JarekTkaczyk's avatar

Btw Eloquent is no facade. It's just an alias for the Model class. I wouldn't worry about the phpstorm.

kevineger's avatar

@mstnorris , is there any way to have the methods in the Eloquent/Builder.php class suggested in php storm? Because currently the findOrFail, update, latest and where (on queries) are being flagged as not found. As mentioned in the original question, I have ran all the install steps for the ide-helper. @JeffreyWay doesn't seem to have this issue in his IDE and he gets code suggestions on the functions listed above.

jettoki's avatar

I've been dealing with the same issue, and it's driving me nuts. The IDE Helper doesn't fix it. I'd rather not memorize every magic method in the framework. Surely there is some way to get auto-complete to cooperate?

jimmck's avatar

You cannot memorize a Magic Method, they are mapped via __call magic method.

Please or to participate in this conversation.