EVOLUTION-MANAGER
Edit File: TramiteCiudadanoController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use GuzzleHttp\Client as GuzzleHttpClient; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Illuminate\Support\Facades\Validator; class TramiteCiudadanoController extends Controller { // private $ulr_tramite = "https://capacitaciontramites.sucre.gob.ec/api/tramite-ciudadano"; public function consultar_index($identificacion=null, $numero_tramite=null){ try{ if(!empty($identificacion) && !empty($numero_tramite)){ #cuando se envian datos $dato['tramite_id'] = $numero_tramite; $dato['identificacion'] = $identificacion; $reglatexto = 'required|regex:/^[A-Za-z0-9ñÑáéíóúÁÉÍÓÚ\s+\/\-.+]+$/'; $validator = Validator::make($dato, [ "tramite_id" => $reglatexto, "identificacion" => $reglatexto ]); if($validator->fails()){ return view('errors.404'); } return view('frontend.tramites.consultar_tramite', compact('identificacion', 'numero_tramite')); }else{ #por defecto return view('frontend.tramites.consultar_tramite'); } } catch (\Throwable $th) { return view('errors.503'); } } public function consultar_historial(Request $request){ try { #validamos que no ingresen caracteres especiales $numero_tramite = $request->numero_tramite; $identificacion = $request->identificacion; $dato['tramite_id'] = $numero_tramite; $dato['identificacion'] = $identificacion; $reglatexto = 'required|regex:/^[A-Za-z0-9ñÑáéíóúÁÉÍÓÚ\s+\/\-.+]+$/'; $validator = Validator::make($dato, [ "tramite_id" => $reglatexto, "identificacion" => $reglatexto ]); if($validator->fails()){ return response()->json([ 'error'=>true, 'status'=>400, 'color'=>'waning', 'mensaje'=>'Información incorrecta' ]); } #======================================= $url_tramite = env('API_TRAMITE_URL'); $api_key = env('API_TRAMITE_KEY'); $client = new \GuzzleHttp\Client(); $url=$url_tramite."/detalle-tramite"; $header=[ 'headers' => [ 'Accept' => 'application/json', 'Authorization' => "Bearer $api_key" ], 'form_params' => $dato, 'connect_timeout' => 60 ]; $response = $client->request('POST',$url,$header); $resultado= json_decode($response->getBody()->getContents()); $historial = []; $tiempo_transcurrido = ""; $dato_tramite = null; $dato_remitente = null; if(isset($resultado->response)){ if(isset($resultado->response->historial_tramite)){ $historial = $resultado->response->historial_tramite; } if(isset($resultado->response->tramite->tiempo_total_transcurrido)){ $tiempo_transcurrido = $resultado->response->tramite->tiempo_total_transcurrido; } if(isset($resultado->response->tramite)){ $dato_tramite = $resultado->response->tramite; } if(isset($resultado->response->remitente)){ $dato_remitente = $resultado->response->remitente; } } return response()->json([ 'error'=>false, 'status'=>200, 'color'=>'success', 'historial'=> $historial, 'dato_tramite' => $dato_tramite, 'dato_remitente' => $dato_remitente, 'tiempo_transcurrido' => $tiempo_transcurrido ]); } catch (\Throwable $th) { // dd($th->getMessage()." - ".$th->getLine()); return response()->json([ 'error'=>true, 'status'=>500, 'color'=>'danger', 'mensaje'=>'Error al obtener el historial' ]); } } }