Understanding Laravel's Context Capabilities
As part of the Laravel 11 release, the core team introduced a new powerful feature called Context that allows you to capture, retrieve, and share information throughout your application during a single request. If you're curious, join me as I guide you through the basic usage, while providing a variety of examples that you can implement within your own projects.
Progress
Series Info
- Episodes
- 6
- Run Time
- 48m
- Difficulty
- Intermediate
- Last Updated
- Jun 27, 2024
- Version
- Laravel 11
Series Episodes
- Concepts and Applications (6)
Introducing Context
Let's explore the basics of Laravel's new Context feature. Learn how it can capture and manage data throughout the lifecycle of a single request.Loading Contextual Data
You can load contextual data anywhere, but it's usually best to load what you need in middleware.Using Context in Jobs
You can use contextual data just about anywhere in your application--including jobs. Let's look at an example contact form to learn how.Testing with Context
Testing code that uses context is easy and straight-forward. It is a dependency injector container, after all.Conditionally Adding Contextual Data
Laravel's Context facade provides many methods you can use to only capture the data you need. We'll look at two of those methods in this episode.Using Stacks and Handling Events
Contexts are useful for tracking a history throughout the life of a request, and stacks are perfect for that purpose. Let's look at how to use them. Let's also look at the hydrated and dehydrating events.
