duanfen7676 2018-09-12 01: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 01: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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部