How to check if ConvertEmptyStringsToNull::class middleware is registered in Laravel 11

37 Views Asked by At

Through Laravel 10, I was able to check if the ConvertEmptyStringsToNull middleware was globally registered by using the following code:

$kernel = $this->getLaravel()->make('App\\Http\\Kernel');

$exists = $kernel->hasMiddleware(\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class);

However, the Kernel class was removed in Laravel 11. How can I check if the ConvertEmptyStringsToNull middleware is registered now?

1

There are 1 best solutions below

0
patricus On

The App\Http\Kernel class was removed from the Laravel 11 skeleton application, but the Illuminate\Foundation\Http\Kernel class is still used by the framework. Additionally, as seen in the index.php, you can resolve the used instance from the Illuminate\Contracts\Http\Kernel interface.

You should be able to update your code to:

$kernel = $this->getLaravel()->make(\Illuminate\Contracts\Http\Kernel::class);

$exists = $kernel->hasMiddleware(\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class);