class HandleCors

Properties

protected Container $container

The container instance.

static protected null|Request): array $configResolver

The closure used to resolve CORS configuration for the current request.

static protected Request): bool> $skipCallbacks

All of the registered skip callbacks.

Methods

__construct(Container $container)

Create a new middleware instance.

Response
handle(Request $request, Closure $next)

Handle the incoming request.

bool
hasMatchingPath(Request $request)

Get the path from the configuration to determine if the CORS service should run.

array
getPathsByHost(string $host)

Get the CORS paths for the given host.

static void
resolveConfigUsing(Closure|null $callback)

Register a closure that resolves CORS configuration for the current request.

static void
skipWhen(Closure $callback)

Register a callback that instructs the middleware to be skipped.

static void
flushState()

Flush all static state.

Details

at line 37
__construct(Container $container)

Create a new middleware instance.

Parameters

Container $container

at line 45
Response handle(Request $request, Closure $next)

Handle the incoming request.

Parameters

Request $request
Closure $next

Return Value

Response

at line 83
protected bool hasMatchingPath(Request $request)

Get the path from the configuration to determine if the CORS service should run.

Parameters

Request $request

Return Value

bool

at line 103
protected array getPathsByHost(string $host)

Get the CORS paths for the given host.

Parameters

string $host

Return Value

array

at line 125
static void resolveConfigUsing(Closure|null $callback)

Register a closure that resolves CORS configuration for the current request.

Boot-only. The closure receives the current request and returns the CORS options array; useful for multi-tenant CORS where the config varies by host or other request data. Persists for the worker lifetime.

Parameters

Closure|null $callback

Return Value

void

at line 136
static void skipWhen(Closure $callback)

Register a callback that instructs the middleware to be skipped.

Boot-only. Skip callbacks persist for the worker lifetime and run on every subsequent request.

Parameters

Closure $callback

Return Value

void

at line 144
static void flushState()

Flush all static state.

Return Value

void