Skip to content

[12.x] Add increment and decrement methods to Context#54976

Merged
taylorotwell merged 1 commit into
laravel:12.xfrom
mattmcdev:context-counter
Mar 12, 2025
Merged

[12.x] Add increment and decrement methods to Context#54976
taylorotwell merged 1 commit into
laravel:12.xfrom
mattmcdev:context-counter

Conversation

@mattmcdev

@mattmcdev mattmcdev commented Mar 11, 2025

Copy link
Copy Markdown
Contributor

This PR proposes adding increment and decrement methods to Context.

This simplifies keeping track of a counter, e.g. number of records added, number of requests made, etc.

@henzeb

henzeb commented Mar 11, 2025

Copy link
Copy Markdown
Contributor

i'd opt for increment, like the Cache facade and Eloquent models have?

@mattmcdev mattmcdev changed the title [12.x] Add counter method to Context [12.x] Add count method to Context Mar 11, 2025
@mattmcdev mattmcdev changed the title [12.x] Add count method to Context [12.x] Add increment and decrement methods to Context Mar 11, 2025
@mattmcdev

Copy link
Copy Markdown
Contributor Author

i'd opt for increment, like the Cache facade and Eloquent models have?

Agreed

Comment thread src/Illuminate/Log/Context/Repository.php
@taylorotwell taylorotwell merged commit 9b060d8 into laravel:12.x Mar 12, 2025
@christophrumpel

Copy link
Copy Markdown
Contributor

@mattmcdev Hey 👋

Do you have a real-world example of how you would use these new methods? Need a good one for the next Whats New video please :-)

@mattmcdev

Copy link
Copy Markdown
Contributor Author

@mattmcdev Hey 👋

Do you have a real-world example of how you would use these new methods? Need a good one for the next Whats New video please :-)

Yep - using Laravel Excel with queued chunked imports, can easily keep track of the number of records inserted throughout that import job.

@christophrumpel

Copy link
Copy Markdown
Contributor

Ah, that's interesting, thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants