Skip to content

Add documentation for Context::scope() #10214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 4, 2025
Merged

Conversation

cosmastech
Copy link
Contributor

Documentation for new Context::scope(). laravel/framework#54799

The `scope()` method provides a way to temporarily modify the context for a given callback and restore to the original state when complete. Any changes made to both context and hidden data within the closure are isolated and automatically discarded once the closure completes. Additionally, you can pass extra data to be merged into the context (as the second and third arguments) while the closure executes.

```php
use Illuminate\Support\Facades\Context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to #10186, we prefer having PHP opening tags in the code sample blocks:

Suggested change
use Illuminate\Support\Facades\Context;
<?php
use Illuminate\Support\Facades\Context;

context.md Outdated
// ]
```

If an object within the context is modified inside the closure, that mutation will be reflected outside the scope. To avoid unintended side effects, use immutable data or create copies as needed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to highlight this:

Suggested change
If an object within the context is modified inside the closure, that mutation will be reflected outside the scope. To avoid unintended side effects, use immutable data or create copies as needed.
> [!NOTE]
> If an object within the context is modified inside the closure, that mutation will be reflected outside the scope. To avoid unintended side effects, use immutable data or create copies as needed.

@taylorotwell taylorotwell marked this pull request as draft February 28, 2025 16:59
@taylorotwell
Copy link
Member

Drafting until release day.

@taylorotwell taylorotwell marked this pull request as ready for review March 4, 2025 21:55
@taylorotwell taylorotwell merged commit 701d69c into laravel:12.x Mar 4, 2025
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.

3 participants