Official Laravel source
AttributeIlluminate\Container\Attributes\Context

#[Context]

In the Container group, #[Context] applies this configuration to the target Laravel element. It accepts 3 configuration parameters.

Available since

Laravel 13.0

Targets

parameter

Parameters

  • $keystring

    Key used to resolve the value. Expected type: string.

  • $defaultmixed

    Fallback value when no result is found. Expected type: mixed.

  • $hiddenbool

    Defines the "hidden" value used by the attribute. Expected type: bool.

Practical usage

use Illuminate\Container\Attributes\Context;

class ReportsController
{
    public function __invoke(#[Context('value', null, false)] mixed $value): array
    {
        return ['status' => 'ok'];
    }
}