Personally, I would do this with a static method, I'm not sure if there is a โrightโ answer, although how can I do it. The way I separate them from the thought that if I do something with an instance of the model, I do this as a normal public function. If I do something in the compilation, I use statics. For instance:
$person = new Person(); $person->setAdmin(true); $person->save();
In the first example, we have a specific instance of Person , and we manipulate it, all the code will simply manipulate this particular instance. In the second example, we act on the entire set of Person , and we want to get a collection of returned objects.
In your case, you will need to initiate a Section instance in order to be able to use your non-static public method, for example:
$section = new Section(); $foundSection = $section->findByIdAndCourseOrFail(7,3);
So, $section becomes a temporary variable that is never used. On the other hand, if you made it static, you could call it without having to do it.
$section = Section::findByIdAndCourseOrFail(7,3);
Hope this makes sense.
source share