I am writing a Laravel console-command. When the command is called using the command-line, I need to know if the ConvertEmptyStringsToNull
is a registered middlewear in the Application or not.
When I looked at Illuminate\Foundation\Http\Kernel I can see that it has a public method called hasMiddleware
that should give me the answer I am looking for.
However, I am not sure what is the correct way to create a new of the App\Http\Kernel
which expends the Illuminate\Foundation\Http\Kernel
class. More, I am not sure if there is a better way to check if the app has a middleware beside creating a new instance of the Kernel
class.
My command class extends the Illuminate\Console\Command like this
use Illuminate\Console\Command;
class TestCommand extends Command
{
public function handle()
{
$router = new \Illuminate\Routing\Router(); // this is not working!
$kernel = new \App\Http\Kernel($this->getLaravel(), $router); // $this->getLaravel() is a method that the Illuminate\Console\Command has which return the instance of the application
}
}
Is there a better way to check if the app has the ConvertEmptyStringsToNull
middleware beside creating a new instance of the Kernel class? Is there a way to access the Kernel class without creating a new instance? If not, what is the proper way to create a new instance of the Kernel class?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire