Skip to content

Bypass accessor when using increment() or decrement() methods #52694

Answered by rodrigopedra
grimmdude asked this question in Ideas
Discussion options

You must be logged in to vote

If you want to use a pure database approach, you can use the underlying Illuminate\Database\Query\Builder@increment() method instead:

User::query()->toBase()->increment('login_count');

public function increment($column, $amount = 1, array $extra = [])
{
if (! is_numeric($amount)) {
throw new InvalidArgumentException('Non-numeric value passed to increment method.');
}
return $this->incrementEach([$column => $amount], $extra);
}

Replies: 2 comments 20 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
20 replies
@grimmdude
Comment options

@rodrigopedra
Comment options

@rodrigopedra
Comment options

Answer selected by grimmdude
@grimmdude
Comment options

@Sophist-UK
Comment options

@grimmdude
Comment options

@Sophist-UK
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
3 participants