我有2个表和3个关系,
首先,奖励表,
奖励标准,
此处标准表自我加入,
将奖励保存在数据库中时,
现在我保存如下,
$award->save();
foreach ($request->criterias as $key => $row) {
$criteria = new AwardCriteria();
$criteria->title = $row['title'];
$criteria->mark = $row['mark'];
$criteria->save();
foreach ($row['sub_criterias'] as $row2) {
$subCrt = new AwardCriteria();
$subCriteria->award_id = $award->id;
$subCriteria->award_criteria_id = $criteria->id;
$subCrt->title = $row2['title'];
$subCrt->mark = $row2['mark'];
$subCrt->save();
}
}
我也可以这样做,
$award->save();
$award->criteria()->saveMany($criteria);
但是在这里如何才能拯救潜在的批评者?你能不能为任何人提出好的方法吗?