Warning when calling the orderBy method statically

0

In the PHPStorm interface a warning message appears stating that I'm calling the orderBy method statically, but it is not static. My call:

Artigo::orderBy('edicao', 'desc')->paginate(25);

Would this be "wrong"? Or would have to do:

(new Artigo)->orderBy('edicao', 'desc')->paginate(25);

Note: I'm using Laravel 5.6

    
asked by anonymous 21.03.2018 / 02:03

1 answer

0

The way you're doing is not wrong, but I think the best way to make models call would be to call them in the __constructor eg.:

private $artigoModel

public function __constructor(Artigo $artigoModel){
    $this->artigoModel = $artigoModel
}

So you can call the $ this-> articleModel article throughout the code and you do not have to instantiate it multiple times if you need it in more than one function.

    
25.03.2018 / 17:41