在 laravel 中检测到字段名的无效 UTF-8
Detected invalid UTF-8 for fieldname in laravel
我正在存储来自第三方的一些回复。有时数据没有存储到数据库中。我检查了 Laravel 日志并发现了一些错误。我正在使用 laravel 5.5 和 mongo db.
感谢任何帮助世界的人。谢谢
Laravel 日志
[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();
您可以通过多种方式处理该问题。其中之一是使用 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();
我正在存储来自第三方的一些回复。有时数据没有存储到数据库中。我检查了 Laravel 日志并发现了一些错误。我正在使用 laravel 5.5 和 mongo db.
感谢任何帮助世界的人。谢谢
Laravel 日志
[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();
您可以通过多种方式处理该问题。其中之一是使用 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();