Have you ever wondered what happens behind the scenes in the Model when we call User::all()
? This is, of course, only one example. In reality, you should understand the difference between such static calls and various other ways to create a new object. Let's explore the details.
Static Methods: Quick Shortcuts
As I mentioned, such a Class::method()
call is a static
way. Under the hood, it's this:
Illuminate/Database/Eloquent/Model.php
public static function all($columns = ['*']){ return static::query()->get( is_array($columns) ? $columns : func_get_args() );}
As you can see, under the hood, it calls...