/** * [Log api] * @param [type] $url [description] * @param [type] $method [description] * @param [type] $request [description] * @param [type] $response [description] */ public static function Logging($url, $method, $request, $response) { $model = new Log(); $data = $model->create(['url' => $url, 'method' => $method, 'header' => json_encode(Request::header()), 'request' => json_encode(Request::all())]); $model = new Log(); $model = $model->findOrFail($data['id']); $model->update(['response' => json_encode($response)]); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $model = new Log(); $url = $request->url(); $method = $request->method(); $data = $model->create(['url' => $url, 'method' => $method, 'request' => 'PARAM : ' . json_encode($request->all()) . ' HEADER : ' . json_encode($request->header())]); $response = $next($request); $model = new Log(); $model = $model->find($data->id); $model->update(['response' => method_exists($response, 'morph') ? $response->morph() : $response]); return $response; }