/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $this->validate($request, ['full_name' => 'required|string']); $duplicate = Member::whereNotIn('id', [$id])->where('full_name', $request->full_name)->where('department_id', Auth::user()->department_id)->first(); if ($duplicate) { return response()->json(true); } $member = Member::where('id', $id)->first(); $member->full_name = $request->full_name; // $member->date_hired = $request->date_hired; // $member->team_leader_id = $request->team_leader_id; // get the difference of months from date hired to present // $tenure = date_diff(Carbon::today(), date_create($request->date_hired))->format("%m"); // $member->experience = $tenure < 3 ? 'Beginner' : (($tenure > 3 && $tenure < 6) ? 'Moderately Experienced' : 'Experienced'); $member->save(); return $member->id; }