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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 openwrt双栈NAT
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用