logo
We provide creative solutions in form of web and mobile applications to clients around the world, creating apps that get attention and meaningful.

Web Development

Mobile Applications Development

Business Solutions

Odoo ERP Implementation

Wordpress Plugins

WordPress Themes

Laravel Development

Server Security

Server Administration

Mobile Marketing

Pay Per Click (PPC) Management

Conversion Rate Optimization

Email Marketing

Online Presence Analysis

Fell Free To contact Us
We are available from Monday to Friday 9AM to 6PM.

+92-323-5531561

talk@appknitters.com

Lahore, Punjab, Pakistan

+92-323-5531561

Lahore, Punjab, Pakistan

Top

Laravel Eloquent: Increments and Decrements

Many times while working on a project, we need to increment value of certain columns in database. Laravel is shipped with some semi-hidden function to do various tasks. One of those are methods to perform increment or decrement on database columns.

Normally we do the increments and decrements this way:


$post = Post::find($post_id);
$post->read_count++;
$post->save();

 

But with Laravel eloquent methods we can do this:


$post = Post::find($article_id);
$post->increment('read_count');

 

Another way of doing this can be:


Post::find($post_id)->increment('read_count');
Post::find($post_id)->increment('read_count', 5); // +5
Product::find($produce_id)->decrement('stock'); // -1
Product::find($produce_id)->decrement('stock',5); // -5

Having more than six years of experince developing custom applications with Laravel, WordPress, Zend, and Cordova.

No Comments

Post a Comment