Courses

PHP for Laravel Developers

Static, New Object and Laravel Auto-Resolving

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Understand static method usage in Laravel
- Learn about service class implementation
- Explore dependency injection and class resolving
- Examine different approaches to object creation

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...

The full lesson is only for Premium Members.
Want to access all 16 lessons of this course? (52 min read)

You also get:

  • 76 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord