_Lumen Version: 5.4.4_
I register the middleware as global one by following line into bootstrap/app.php:
$app->middleware([
App\Http\Middleware\ResponseLoggerMiddleware::class,
]);
handle() will be called as expected but terminate() will not.
And, the middleware is:
namespace App\Http\Middleware;
use App\Jobs\LogResponseJob;
use Closure;
class ResponseLoggerMiddleware {
public function handle($request, Closure $next) {
return $next($request);
}
public function terminate($request, $response) {
// dd('called');
}
}
Note: I'm not using the middleware along with routes because I know it is registered globally.
Same here, can't seem to get terminate() to work even though handle() is called.
The dd won't work because at the point where terminate is called the response is already returned, have you tried Log?
I have the very same issue, lumen framework 5.4 with dingo/api loaded and this code in middleware
`namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\FacadesLog;
class Logging
{
public function handle($request, Closure $next)
{
Log::info("Accessing [" . __FUNCTION__ . "]");
return $next($request);
}
public function terminate($request, $response)
{
Log::info("Accessing [" . __FUNCTION__ . "]");
}
}`
Apparently the terminate is never called... perhaps i am doing something wrong.. here is the entry in bootstrap/app.php
$app->middleware([
'logging' => App\Http\Middleware\Logging::class,
]);
handle works just fine..but terminate is never hited.
I've also tried to register the middleware on route and declare it in route for testing purpose..but same issue is happening, handle is hit but not terminate.
Can someone point to me where I'm doing wrong?
Thanks
Same here, handle works fine but terminate is never called. Weirdly enough terminate is called when running tests 馃
Same here,why?
Seems to be fixed in the latest release. Please update to 5.7.
Im using 5.7.6 and the problem wasn't solved in routeMiddleware, the method terminate is never called
@leocarmo works for me. Can you first please try one of the following support channels? If you can actually identify this as a bug, feel free to report back.
Most helpful comment
The
ddwon't work because at the point whereterminateis called the response is already returned, have you triedLog?