Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Laravel stops with Non-static method ... cannot be called statically

Your error

Non-static method App\Models\User::getActive() cannot be called statically2 more lines it can show

Fix it fast

Most common cause, 1 of 3

A public method on an Eloquent model is called as User::method()

Turn query helpers into local scopes.

Fix
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    #[Scope]
    protected function active(Builder $query): void
    {
        $query->where('active', 1);
    }
}

// caller
$users = User::active()->get();
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

PHP 8 throws Non-static method X::foo() cannot be called statically when an ordinary method is called with ::. Laravel reroutes static calls through __callStatic only for unreachable methods, so a public model method, the Illuminate\Http\Request class used as a facade, or a plain service class fails. Use #[Scope], import the facade, or inject the class. Laravel 13, PHP 8.3+.

  • Applies to Laravel 13.43, PHP 8.4, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Note the class inside the message, then list the imports of the file named first in the stack trace. An App\Models class points to cause 1, Illuminate\Http\Request to cause 2, and another class of yours to cause 3.

Run this first
grep -n "^use " app/Http/Controllers/OrderController.php

Then find the line you see in this list and open its fix:

  1. 1A public method on an Eloquent model is called as User::method()The class in the message lives under App\Models, and the method is declared public function without static
  2. 2Illuminate\Http\Request is imported, but the code calls it like a facadeThe message names Illuminate\Http\Request, and the file has use Illuminate\Http\Request; followed by Request::input() or Request::all()
  3. 3A plain service class is called with ::The class is one of yours, such as App\Services\ReportService, with no facade behind it, and the caller writes ReportService::build()

What does the error look like?

  • Non-static method App\Models\User::getActive() cannot be called statically
  • Non-static method Illuminate\Http\Request::input() cannot be called statically
  • Error: Non-static method App\Services\ReportService::build() cannot be called statically

Cause 1 of 3

A public method on an Eloquent model is called as User::method()

You seeThe class in the message lives under App\Models, and the method is declared public function without static

Check

Non-static method App\Models\User::getActive() cannot be called statically means the model method is public and not static. PHP calls __callStatic only for methods that are inaccessible in a static context, and Eloquent's Model::__callStatic is what turns User::something() into a query, so a public instance method never reaches it and PHP raises the Error.

Check
grep -n "public function getActive" app/Models/User.php

Fix

Turn query helpers into local scopes. Laravel 13 marks them with the #[Scope] attribute on a protected method, which keeps the method inaccessible from outside so the static call is routed to the query builder.

Fix
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    #[Scope]
    protected function active(Builder $query): void
    {
        $query->where('active', 1);
    }
}

// caller
$users = User::active()->get();

Verify

The scope returns a count instead of throwing the Error.

Verify
php artisan tinker --execute="dump(App\Models\User::active()->count());"

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

Illuminate\Http\Request is imported, but the code calls it like a facade

You seeThe message names Illuminate\Http\Request, and the file has use Illuminate\Http\Request; followed by Request::input() or Request::all()

Check

All Laravel facades sit in the Illuminate\Support\Facades namespace, and the facade reference lists Illuminate\Http\Request as the class the Request facade stands for. With the class imported instead of the facade, Request::input() is a direct static call to an instance method.

Check
grep -rn "Request::" app/ routes/

Fix

Keep the class import and let Laravel inject the current request into the controller method, then call methods on that object. Importing Illuminate\Support\Facades\Request also works if you want the static style.

Fix
use Illuminate\Http\Request;

class OrderController extends Controller
{
    public function store(Request $request)
    {
        $email = $request->input('email');
        // ...
    }
}

Verify

Posting to the route returns your normal response and the log shows no new Error.

Verify
php artisan test --filter=OrderController

Confirmed by laravel.com

Did this fix it?

Cause 3 of 3

A plain service class is called with ::

You seeThe class is one of yours, such as App\Services\ReportService, with no facade behind it, and the caller writes ReportService::build()

Check

An ordinary PHP class has no static proxy, so ReportService::build() on a public instance method runs into the PHP 8 rule that calling non-static methods statically throws an Error. Before PHP 8.0 the same call only produced an E_DEPRECATED warning, which is why older code may still contain it.

Check
grep -rn "ReportService::" app/

Fix

Inject the service through the constructor or the method and call it on the instance; the service container builds it for you. To keep the static look, import it with the Facades\ prefix as a real-time facade.

Fix
// Option 1: injection
public function show(\App\Services\ReportService $reports, string $month)
{
    return $reports->build($month);
}

// Option 2: real-time facade
use Facades\App\Services\ReportService;

ReportService::build($month);

Verify

The page that called build() renders, and the Error is gone from the log.

Verify
php artisan test --filter=Report

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Write every reusable query condition as a #[Scope] method, so model helpers never need to be public instance methods called with ::.
  • When the editor auto-imports Request, check which one it picked: only Illuminate\Support\Facades\Request supports static calls.
  • In controllers, type-hint Illuminate\Http\Request instead of importing it and calling it statically.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Spotless Laundry, EZ Estimater.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.