⚡️ Ray 3.0 launch sale! Discounts and lifetime licenses available for d h m s
Back to overview

Ray now supports Laravel 11's Context

1 April 2024

Image of Freek

Freek

Laravel 11 recently introduced a nice new feature called Context. We’ve updated Ray with a convenient method to display all set context.

What is Context?

This feature allows you to set some values anywhere in your app as context.

use Illuminate\Support\Facades\Context;

Context::add('url', $request->url());
Context::add('trace_id', Str::uuid()->toString());

You can easily retrieve the set values anywhere in your app.

use Illuminate\Support\Facades\Context;

Context::all(); // returns all context

Now, this isn’t all that special. With the examples given above, you’d be right to think that Context is just some array-backed cache.

But Context's special feature is that it makes all of this information available to any job dispatched in the request where context was set.

dispatch(new MyJob()); // this job will receive the context
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Context;

class MyJob implements ShouldQueue
{
    public function handle()
    {
        // returns the context that was
        // set in the request that dispatched
        // this job
        $allContent = Context::all();

        // do some work
        // ...
    }
}

Context in Ray

Ray now has a new method, aptly named context, showing all set context.

ray()->context(); // displays all context

ray()->context('key', 'key2'); // displays only the given keys

Context can also be invisible. You can display those values using the hiddenContext method.

ray()->hiddenContext(); // displays all hidden context

ray()->hiddenContext('key', 'key2'); // displays only the given hidden keys

Stay in the loop with updates & promotions for Ray

We only send a few emails a year.

Debug without breaking your flow

Ray keeps all your debug output neatly organized in a dedicated desktop app.

Launch sale! Lifetime licenses also available

Ray licenses are valid for 1 year and managed through Spatie. VAT is calculated during checkout.