duanfen7676 2018-09-12 09:12
浏览 157
已采纳

检测到laravel中fieldname的无效UTF-8

I am storing some response from a third party. Sometimes data is not storing in to database. I checked the Laravel log and getting some error. I am using laravel 5.5 and mongo db.

Any help world be appreciated. Thanks.

Laravel log

[2018-09-10 11:40:50] production.ERROR: Detected invalid UTF-8 for fieldname "shipping_city": München  
[2018-09-10 11:41:03] production.ERROR: Detected invalid UTF-8 for fieldname "_id": Ã$zjmêá¹ëmy×
[2018-09-10 11:48:16] production.ERROR: Method [error] does not exist on [App\Http\Controllers\PaymentController]. {"userId":"5b0d2b6f12236ca36a2282ed","exception":"[object] (BadMethodCallException(code: 0): Method [error] does not exist on [App\\Http\\Controllers\\PaymentController]. at /var/www/vhosts/cabin-holiday.frontend/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:68)

PaymentController.php

$payment        = new Payment;

   foreach($_POST as $key => $value) {
     if(Schema::hasColumn($payment->getTable(), $key)){
        if(is_array($value)) {
           $payment->{$key} = $value[1];
        } else {
                $payment->{$key} = $value;
                }
      }
    }
$payment->save();
  • 写回答

1条回答 默认 最新

  • dongzou3751 2018-09-12 09:21
    关注

    Couple of ways you can handle that. One of them is to use utf8-encode

    string utf8_encode ( string $data )
    

    PaymentController.php

    $payment = new Payment;
    
       foreach($_POST as $key => $value) {
         if(Schema::hasColumn($payment->getTable(), $key)){
            if(is_array($value)) {
               $payment->{$key} = utf8_encode($value[1]);//changes
            } else 
            {
                        $payment->{$key} = utf8_encode($value);//changes
    
            }
    
            }
            }
        $payment->save();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答