/// тип поля 'year' - это год, когда метод Carbon работает на первом ряду, но не на втором
public function store(Request $request)
{
$evaluationM = new Monthly_evaluation();
$evaluationM->users_id = $request->input('users_id');
$evaluationM->discipline = $request->input('discipline');
$evaluationM->date = $request->input('date');
$evaluationM->result = $evaluationM->discipline;
$evaluationM->annual_evaluations_id = 1;
$id = $request->input('users_id');
$date = $request->input('date');
$year = Carbon::createFromFormat('Y-m', $date)->year;
$evaluationA = Annual_evaluation::where('users_id', $id)
->where('year', '=', $year)
->get();
if (count($evaluationA) == 0) {
$evaluationA = new Annual_evaluation();
$date = $request->input('date');
$year = Carbon::createFromFormat('Y-m', $date)->year;
$evaluationA->year = $year;
$evaluationA->result = $evaluationM->result;
$evaluationA->users_id = $request->input('users_id');
$evaluationA->save();
$evaluationM->annual_evaluations_id = $evaluationA->id;
} else {
foreach ($evaluationA as $ea) {
$evaluationM->annual_evaluations_id = $ea->id;
$result = $ea->result;
$result = $result + $evaluationM->result;
$ea->result = $result;
$ea->save();
}
}
$evaluationM->save();
return redirect('staff/staff');
}