I used the code below to register each request and response for my API, but now it does not work for Laravel 5.2.
I tried using https://laravel.com/docs/5.2/middleware#terminable-middleware , but failed.
use Closure; use Illuminate\Contracts\Routing\TerminableMiddleware; use Illuminate\Support\Facades\Log; class LogAfterRequest implements TerminableMiddleware { public function handle($request, Closure $next) { return $next($request); } public function terminate($request, $response) { $logFile = 'log.txt'; Log::useDailyFiles(storage_path().'/logs/'.$logFile); Log::info('app.requests', ['request' => $request->all(), 'response' => $response->getContent()]); } }
Can someone suggest me a solution?
I have a solution. the problem was that I added "die" in the controller method, due to which the completion function is not executed, and therefore the log is not generated.
, web .php, app/Kernel.php $middlewareGroups web :
web
app/Kernel.php
$middlewareGroups
\App\Http\Middleware\LogAfterRequest ::class,
routes.php :
routes.php
Route::group(['middleware' => 'web'], function () { // here you put all the routes });
Source: https://habr.com/ru/post/1687412/More articles:scala - why map.size returns 0 when the map is not empty - scalaWhy does my card claim that it does not have keys after adding keys? - scalaWithDefaultValue behavior in mutable.Map - scalaLaravel auth does not display session message - authenticationПочему для перегружаемой функции вставки/извлечения требуется аргумент ostream/istream? - c++Back button not set correctly in iOS 11 - ios11Отображение данных JSON в элементе, использующем цикл for в JavaScript. - jsonGet data from ajax to mvc action - javascriptHow to create a plugin dashboard using Angular 4? - angularкак разработать более эффективный цикл с использованием подчеркивания + ES 6 - javascriptAll Articles