【发布时间】:2021-06-28 09:52:46
【问题描述】:
我尝试将 JSON 格式的文件导入 MySQL 数据库。我把这段代码放在web.php中:
Route::get('/pages', function(){
$json = file_get_contents(storage_path('posts_and_comments.json'));
$objs = json_decode($json,true);
foreach ($objs as $obj) {
foreach ($obj as $key => $value) {
$insertArr[Str::slug($key,'_')] = $value;
}
DB::table('my_likes')->insert($insertArr);
}
dd("Finished adding data in examples table");
});
它给了我一个 ErrorException 数组到字符串转换 Laravel。我该如何解决? 谢谢!
【问题讨论】: