-
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Instead of manually having to add the middlewares globally, then we could add a config (default disabled
) to automatically push these middlewares to the global stack.
This is done in itsgoingd/clockwork
protected function registerMiddleware(): void
{
// The interface does not have the methods hasMiddleware() and prependMiddleware() but the actual implementation does
$kernel = $this->app[\Illuminate\Contracts\Http\Kernel::class];
if (method_exists($kernel, 'hasMiddleware') && $kernel->hasMiddleware(ClockworkMiddleware::class): {
return;
}
if (! method_exists($kernel, 'prependMiddleware')) {
return;
}
$kernel->prependMiddleware(ClockworkMiddleware::class);
}
And also in Laravel Jetstream even without the checks.
protected function bootInertia()
{
$kernel = $this->app->make(Kernel::class);
$kernel->appendMiddlewareToGroup('web', ShareInertiaData::class);
$kernel->appendToMiddlewarePriority(ShareInertiaData::class);
if (class_exists(HandleInertiaRequests::class)) {
$kernel->appendToMiddlewarePriority(HandleInertiaRequests::class);
}
// ...
}
Question: Is there no better way? It seems incorrect to "assume" (or check for existence) of methods not defined on the interface.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request