Warning when calling orderby method statically

Asked

Viewed 36 times

0

In the Phpstorm interface is displayed a warning message stating that I am calling the orderby method in a static way, however, this is not static. My call:

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

Would that be "wrong"? Or would I have to do:

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

Note: I am using Laravel 5.6

  • To access a method or object field, you should use the arrow operator -> I just saw the scope resolution operator :: being used to determine methods and Class/static fields in php

  • This is called Facade gives a search in Laravel’s documentation

  • 2

    https://laravel.com/docs/5.6/facades of a read and ignore Phpstorm message it is not a problem to use the first shape

  • I took a look at large projects, it is normal/common this approach from what I could observe.

  • No problem, the first form is correct yes.

1 answer

0

The way you are doing it is not wrong, but I think the best way to call the models would be to call them in __constructor ex.:

private $artigoModel

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

So you can make the call for $this->articleModel throughout the code and you don’t need to be instantiating several times if you need it in more than one function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.