В моем Laravel -5.8 у меня есть этот код:
public function findScore(Request $request)
{
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$identities = DB::table('appraisal_identity')
->select('id')
->where('company_id', $userCompany)
->where('is_current', 1)
->first()
->id;
$child = DB::table('appraisal_goal_types')
->where('company_id', $userCompany)
->where('id', $request->id)
->first();
$parentid = DB::table('appraisal_goal_types')
->select('parent_id')
->where('company_id', $userCompany)
->where('id', $request->id)
->first()
->parent_id;
$childid = DB::table('appraisal_goal_types')
->select('id')
->where('company_id', $userCompany)
->where('id', $request->id)
->first()
->id;
if(empty($child)) {
abort(404);
}
$weightedscore = 0;
$weightedscore = DB::table('appraisal_goals')
->select(DB::raw("IFNULL(SUM(weighted_score),0) as weighted_score"))
->where('appraisal_identity_id', $identities)
->where('employee_id', $userEmployee)
->where('parent_id', $parentid)
->first();
$weightedscorex = 0;
$weightedscorex = DB::table('appraisal_goals')
->select('weighted_score')
->where('appraisal_identity_id', $identities)
->where('employee_id', $userEmployee)
->where('id', $childid)
->first();
$maxscore = DB::table('appraisal_goal_types')
->select('max_score')
->find($child->parent_id);
return response()->json([
'maxscore' => $maxscore->max_score,
'weightedscore' => $weightedscore->weighted_score,
'weightedscorex' => $weightedscorex->weighted_score
]);
}
Когда я запускаю код, я получаю эту ошибку:
jquery .min . js: 2 GET http://localhost: 8888 / laraproject / get / findScore? Id = 2 500 (внутренняя ошибка сервера)
Затем я обнаружил, что ошибка находится в этой строке:
$weightedscorex = DB::table('appraisal_goals')
->select('weighted_score')
->where('appraisal_identity_id', $identities)
->where('employee_id', $userEmployee)
->where('id', $childid)
->first();
, поскольку значение равно нулю, а таблица пуста.
Как мне ее разрешить?
Спасибо