Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lugi's avatar
Level 21

How to avoid error that non-static Model method should not be called statically

I would like to increment price for all items.

Using Tinker I can normally do that by calling:

>>> App\Item::increment('price', 100)
=> 33

But if I do that using function in Item model, I get error:

>>> App\Item::increasePrice(100)
PHP Deprecated:  Non-static method Illuminate\Database\Eloquent\Model::increment() should not be called statically in ...\project1\app\Item.php on line 59
// ...
class Item extends Model
{
    //...
    public static function increasePrice($value)
    {
        Item::increment('price', $value);
    }
    //...
}

What am I doing wrong ?

thanks...

0 likes
5 replies
jaec86's avatar

I don’t think you need a wrapper method in your model. Keep using increment method.

If you really want to use a wrapper method you shoul change Item::increment for $this->increment

Lugi's avatar
Level 21

@jaec86 thanks for answering.

For some reasons :-) I need wrapper method.

$this->increment() doesn't work because it is inside static function increasePrice...

crnkovic's avatar

increment is not static method, that means it only works on an object. Class Item by itself is not an object until you make an instance of it. You make an object by grabbing a record from the database and mapping it to the class instance.

So, you can grab an item from the database, increase the price and do that for all items.

Such as: (untested)

Item::all()->each->increment('price', $value);

or


foreach (Item::all() as $item) {
    $item->increment('price', $value);
}

Or, if you need performance, do bulk update using raw queries.

thoasty's avatar

Use

Item::query()->increment('price', $value);
arthurvillar's avatar
Level 9

When you call a method with the :: like in Class::method(), it is implied that the method is static. @thoasty answer is correct, but just for the sake of clarity and consistency, I would use self instead of Item, like so

// ...
class Item extends Model
{
    //...
    public static function increasePrice($value)
    {
        self::query()->increment('price', $value);
    }
    //...
}

Please or to participate in this conversation.