【问题标题】:Laravel Json read in ControllerLaravel Json 在控制器中读取
【发布时间】:2021-09-08 04:35:24
【问题描述】:

我正在使用 Laravel 并尝试在控制器中读取 json 以清理 1 个特定数据...并将所有 json 传递给查看(最后一个现在正在工作)

$url= 'https://example.com/api;
        $client = new \GuzzleHttp\Client();
        $res = $client->get($url);
        $content = (string) $res->getBody();
    
        $customers= json_decode($content, true);

        $firstNumbers = substr($content->numbertotal, 0, 2);

        $latestNumber = substr($string, -1);

        return [$customers, $firstNumbers, $latestNumber];

实际上我使用data["customer"]["denominacion"] 仅显示“客户名称”,例如 en view...

但我需要...在总数中...例如:1122222223 仅恢复... 11 和 3 以将其保存在数据库中。有什么可以帮助我的吗?

我的 json 是:

{"result":"success","customer":{"nro_evento":2960505,"nro_secuencia_contacto":1,"Tipo_contacto":{"Cod_contacto":1,"Descripcion":null,"Visible":null,"Representante":0},"numbertotal":1122222223,"tipo_doc":0,"Tipo_doc_desc":null,"denominacion":"NOMBRE Y APELLIDO","telefono":0,"celular":0,"proveedor_celular":0,"mail":"","cod_area_tel":"","cod_area_cel":"","HabilitadoImpuestos":true}}

我不能只调用控制器中的“numbertotal”值...

提前致谢!

【问题讨论】:

    标签: json laravel substr


    【解决方案1】:

    已解决,我添加了一个带有 numbertotal 的隐藏输入...我创建了一个 get in store 函数...并应用 substr。

    【讨论】:

      猜你喜欢
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      • 2016-02-21
      • 2014-08-15
      • 1970-01-01
      相关资源
      最近更新 更多