Why I'm getting 'Non-static method should not be called statically' when invoking a method in a Eloquent model?

Why I'm getting 'Non-static method should not be called statically' when invoking a method in a Eloquent model?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why I'm getting 'Non-static method should not be called statically' when invoking a method in a Eloquent model?

You are encountering this error because of a fundamental mismatch between how PHP resolves static calls and how Eloquent models operate. When you write Post::getAll(), you are instructing the engine to call a public, static function on the Post class. However, your implementation defines getAll() as an instance method. It relies on $this, which refers to the current model instance.

Static methods do not have access to $this. When PHP attempts to resolve Post::getAll(), it looks for a standard static definition (like a factory pattern or a helper). Finding none, it falls back to calling the method on the class namespace, but since the method signature expects an object context, PHP throws the "Non-static method... should not be called statically" exception.

To fix this, you must align your controller logic with your model's architecture. There are two primary approaches depending on whether getAll() is meant to be a factory pattern or a query helper.

Option 1: Refactor as an Instance Method

The most common scenario involves creating a custom scope or a specific query builder helper within the model. In this case, you should remove the static call from your controller. Instead of calling the method directly on the class name, you must instantiate the model first.

Update your controller to resolve the model from the service container or use new (though dependency injection is preferred in larger applications):

use App\Models\Post;

public function index()
{
    $post = new Post(); // Or use Post::class if injecting via container
    
    return $post->getAll();
}

Your model definition should remain exactly as you wrote it:

public function getAll()
{
    return $this->all()->take(2)->get();
}

By instantiating Post first, $this inside the method now refers to a valid object. The logic executes against that specific instance, fetching all records and limiting them to two before returning the collection. This approach preserves your existing logic without altering the internal implementation of getAll().

Option 2: Implementing Static Query Helpers

If your intention was to call this method statically (e.g., Post::getAll()), you cannot rely on $this->all() inside a static context because there is no model instance to query. You must rewrite the logic to use the global static keyword or simply remove the dependency on an instance variable.

Here is how you would refactor the method to support a static call:

public static function getAll()
{
    return static::all()->take(2)->get();
}

Using static::all() allows late static binding, meaning that if you extend this model later (e.g., AdminPost), the query will resolve against the correct class. This is often the preferred pattern for global actions like retrieving a list of items.

Understanding the Trade-offs

Choosing between these methods impacts your codebase's flexibility. If you stick with Option 1, you are treating getAll() as a business logic layer that requires state. If you move to Option 2, you are defining it as a repository-style query helper.

A common pitfall developers face is mixing these patterns. For instance, attempting to use static::all() inside an instance method without checking the context can lead to unexpected behaviors if the class hierarchy changes. Conversely, calling instance methods statically breaks immediately, as seen in your error message.

Another consideration involves the all() query itself. Calling $this->all() inside a static context is invalid because all() requires a database connection bound to an instance of the model. By switching to static::all(), you ensure the query builder is initialized correctly for the class being called.

If you are looking for more advanced patterns on how to structure these queries or handle complex scopes within Eloquent, resources like https://laravelcompany.com offer detailed guides on building scalable Laravel architectures that avoid these common static/instance confusion traps.

Our network