php - 使用 Laravel Eloquent 传递在函数中调用的数组值
问题描述
我不确定我的下一步是什么,或者我需要做哪些格式化才能将这些值插入数据库。
目前我正在调用以数组形式返回数据的函数。
$rfvFieldID = $this->function1(); // array
$rfvIDs = $this->fucntion2(); // array
我将这些值传递给一个新表并创建一个具有父子节点的数据。
foreach ($rfvIDs as $rfvID ) {
$parentID = DB::table('table1')->insertGetId([
'name' => $this->sessions['name'],
'description' => $this->sessions['description'],
'status' => 1,
'plan_id' => $rfvID, // this contains few columns but want to save the ID only
'created_at' => new DateTime(),
'updated_at' => new DateTime(),
]);
foreach ($parentID as $child) {
$child = DB::table('yomm_pathway_plan_group')->insertGetId([
'name' => $this->sessions['name'],
'description' => $this->sessions['description'],
'status' => 1,
'group_id' => $pathwayGroupID,
'plan_id' => $rfvID,
'created_at' => new DateTime(),
'updated_at' => new DateTime(),
]);
}
}
逻辑在每个 $rfvID 上,它将包含 $rfvFieldID(例如 1、2、3)。需要你帮忙 小伙子们
谢谢
解决方案
推荐阅读
- java - Webview 将值传递给 SAPUI5 控制器
- ssis - BIML 中的连接字符串
- c# - Selenium自动下载文件c#
- python - 将弹性集群数据读入 python 数据框
- c++ - 在模板函数参数中使用 std::bind
- python - 使用 python 将缓冲区发送到 HID
- compiler-errors - 从“double”到“System::TVarRec”的转换不明确
- c# - 如何根据某些条件执行除一条语句之外的所有语句?
- java - JCombobox 箭头消失
- node.js - Cloud Functions 和 Firestore:迭代 document.data