我建立了一个计算复数的报告,并且使用了ajax。
该代码可在我的本地主机上完美运行,但在服务器上会抛出500条内部错误,而没有任何消息。我尝试在每个代码块之后使用dd
,而这正是引发错误的那部分
$decoded_needs = [];
foreach ($needs_teacher as $needs) {
$decoded_needs[] = json_decode($needs->training_needed);
}
if (empty($decoded_needs)) {
$training_needs_teacher = array(['0' => 'None']);
} else {
$sanitized_needs = [];
foreach ($decoded_needs as $key => $items) {
foreach ($items as $index => $item) {
foreach ($item as $name => $bit) {
$sanitized_needs[$name][] = $bit;
}
}
}
$s_standards = [];
$s_sub_category = [];
// dd() works here
foreach ($sanitized_needs['standard'] as $skey => $standard) {
$sname = DB::table('lesson_observation_teacher_standards')->where('id', $standard)->first()->name;
$s_standards[] = $sname;
foreach ($sanitized_needs['sub_category'] as $key => $substandard) {
$name = DB::table('lesson_observation_teacher_standard_categories')->where('id', $substandard)->first()->name;
if ($key == $skey) {
$s_sub_category[$sname][] = $name;
}
}
}
// but not here
$training_needs_teacher = [];
foreach ($s_sub_category as $key => $index) {
foreach ($index as $items) {
$training_needs_teacher[$key] = array_count_values($index);
}
}
$sanitized_needs = [];
foreach ($training_needs_teacher as $key => $items) {
foreach ($items as $index => $item) {
$sanitized_needs[$key . ":" . count($items)][] = $index . ":" . $item;
}
}
$training_needs_teacher = $sanitized_needs;
}
我知道我可以在许多情况下使用WhereIn
,但我需要重复的物品。我只想知道是否有解决此问题的方法?
请注意,我的ajax包含csrf令牌。
答案 0 :(得分:1)
我认为问题在于通往数据库的路径
我已经解决了这个问题,您必须对路径进行三重检查,在您的本地环境中,您的站点可能位于根路径,因此DB ::可以正常工作,但在生产中,您应该在数据库引用之前放置一些内容,例如\ rootFolder \ DB ::
希望对您有帮助。