首页 > 解决方案 > 如何在不重复 Laravel 的情况下合并拖曳数组

问题描述

我可以制作一个 crud mongo,但我需要将 mongo mysql 与来自 mongo 的特定 col 关联或合并我有一个集合 Notes,每个文档都有,

{
"_id":{"$oid":"607f2cdf24670000e40066c9"},
"curse_id":47,
"secion":"A",
"block":4,
"activities":[],
"scores":[]
}

在 mysql 中,我有一张桌子,那里有学生

id  name    Curse   secion
1   Jon     47      A
2   Matew   47      A
3   Jane    48      B
4   Joly    48      A
  1. case 1 Get all students with own cols where curse 74 seccion A from mongo 注意 -> 分数需要存储和更新 cols{} 分数,问题是 case2

  2. 案例 2 从 mysql 获取诅咒 74 seccion A 的所有学生文档注释 -> 分数

    “分数”:[

    {“id”:1, “Jon”  , cols{2:10, 3:20}  },
    
    {“id”:2, “Matew”, cols{2:50, 3:60}  },
    

    ]

我将创建 cols dinamicals

控制器 laravel student.php

function getDocStudents(){
       $docID =[
            "curso_id"=> (int) $request->curso_id,
            "seccion"=> $request->seccion
        ];

       $nota = Notes::where($docID)->first(); //mongo

        if(is_null($nota)){
              $nota = new Notes();
              $nota->curse_id     = $request->curse_id,
              $nota->seccion      = $request->section
              $nota->block       = $request->block;
              $nota->activities  = [];
              $nota->scores       = [];
              $nota->save();
        }
        
        $resp['student'] = Students::where($docID)->get(); //come from mysql
        $resp['doc']  = $nota;
        return response()->json($resp);
}

标签: javascriptmysqlarrayslaravelmongodb

解决方案


推荐阅读