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
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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...
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.