<?php

namespace App\Http\Middleware;

use App\Classes\General\LogHelper;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class LogRequestPathMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if(env('APP_ENV') !== 'local'){
            $method = $request->method();
            $fullUrl = $request->fullUrl();
            LogHelper::channel('request_path')->info('Request Method: ' . $method);
            LogHelper::channel('request_path')->info('Request URL: ' . $fullUrl);


            if ($request->isMethod('post')) {
                $payload = $request->all();
                LogHelper::channel('request_path')->info('Request Payload POST: ', $payload);
            }
        }

        return $next($request);
    }
}
