01 April 2024
Freek
Ray now supports Laravel 11's Context
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
Understand and fix bugs faster
Ray is a desktop application that serves as the dedicated home for debugging output. Send, format and filter debug information from both local projects and remote servers.