Registering an After Application Filter

Problem

You want to do work after every request in your application.

Solution

Register a "after" application filter.

App::after(function($request, $response)
{
    // Capture last response
    $content = $response->getContent();
    File::put(storage_path().'/logs/last_response.txt', $content);
});

Discussion

You can modify the response.

Since after filters receive the response object, you can make changes to the response within this filter. See Understanding the Request Lifecycle to understand exactly when application after filters are called.

comments powered by Disqus