首页 > 解决方案 > 使用 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)。需要你帮忙 小伙子们

谢谢

标签: phplaravel

解决方案


推荐阅读