David Chavarria
David Chavarria

Reputation: 135

How to make a query with Eloquent in Laravel 5.8?

What I want to do is the equivalent of this consultation using Eloquent, but I have no idea how to do it.

update promociones set veces_cajeadas=veces_cajeadas + 1 where id = 7

What I need is that when a specific promotion id is chosen, add 1 to a field in the table. The model for the table is Promotions.

Upvotes: 0

Views: 121

Answers (1)

Milad Teimouri
Milad Teimouri

Reputation: 1211

in laravel eloquent and even query builder, there is a convenient way to decrease and increase values of model

$promotions = Promotions::find($id);
$promotions->increment('veces_cajeadas')

for more information about these methods you can read laravel doc

Upvotes: 1

Related Questions