How To Test Laravel Middleware

[Solved] How To Test Laravel Middleware | Php - Code Explorer | yomemimo.com
Question : how to test laravel middleware

Answered by : famous-flatworm-jobjpt34hokw

// Suppose that you have a middleware Jwt.
// Create a request
$request = new Request;
// Customize the request
$request->headers->set("Authorization", "Bearer eyJhbGciOiJIUzI1NiJ9.eyJSb2xlIjoiQWRtaW4iLCJJc3N1ZXIiOiJJc3N1ZXIiLCJVc2VybmFtZSI6IkphdmFJblVzZSIsImV4cCI6MTY1OTI5MDcyNywiaWF0IjoxNjU5MjkwNzI3fQ.R-7EJUMW3er4BJdeEXkPrHbi_HErEI4WPDoIbp89fyU");
// Get the response
$response = (new Jwt) ->handle($request, fn () => null) ->getContent();

Source : | Last Update : Sun, 07 Aug 22

Answers related to how to test laravel middleware

Code Explorer Popular Question For Php