【发布时间】:2021-10-27 01:00:33
【问题描述】:
我正在尝试使用以下代码插入一个数组。
$notif = new Notification();
$notif->recipient_id = auth()->user()->id;
$notif->sender_id = auth()->user()->id;
$notif->unread = true;
$notif->content = "Top up voucher {$voucher->id} | $amount dalam proses";
$notif->type = 'topup';
$link[] = [
'route_name' => 'topup.detail-confirm',
'param' => ['param_name' => 'id', 'param_value' => $transaction->id]
];
$notif->link = $link;
$notif->save();
我收到以下错误。
数组到字符串的转换
【问题讨论】:
-
哪一行?什么确切的错误?
-
$notif->link = $link;
-
我认为 MySQL 不支持
array数据类型。因此,您需要先将数组转换为JSON string,然后再将其存储到数据库中。