Nursultan  Aubakirov
Nursultan Aubakirov

Reputation: 87

Laravel 5, Method 'findOrFail' not found in class

I'm learning Laravel 5 from the Laracast course: Laravel 5 Fundamentals, using PhpStorm IDE.

I have issue with the static methods of model, such as where(), find(), and findOrFail().

When I use these methods PhpStorm shows:

Method 'findOrFail' not found in class App\Article.

My model is Article, and the method all() works.

How can I solve this?

Upvotes: 3

Views: 6007

Answers (4)

K0r5hun
K0r5hun

Reputation: 313

Now you can use Laravel IDE helper and for properly recognition of Model methods (i.e. paginate, findOrFail) add comment for your model class

/** @mixin \Eloquent */

Upvotes: 6

Mohamed Saif
Mohamed Saif

Reputation: 11

I had the same problem, it turned at the end that I had forgotten a single quotation mark in show.balde.php when I extended the master page: @extends('app) when I finally realized it and fixed it everything worked perfectly: this worked: $article = Article::findOrFail($id); and this also worked: $article = Article::query()->findOrFail($id); I hope this helps (I tried this in Laravel 5.3).

Upvotes: -1

Nursultan  Aubakirov
Nursultan Aubakirov

Reputation: 87

Thank you for interesting. But I solved, I use query() method:

  public function show($id)
    {

        $article = Article::query()->findOrFail($id);

       return view('articles.show', compact('article'));

    }

Upvotes: 4

user1669496
user1669496

Reputation: 33068

It's because those methods are hitting the magic method __call which phpStorm does not know how to follow. It's really just a shortcut for the following...

$article = new \App\Article;
$query = $article->newQuery();

$query->where('column', 'value')->get();

Upvotes: 2

Related Questions