/** * Post Update * * @return Redirect */ public function postUpdate() { $Companionship = Companionship::find(Input::get('id')); $Companionship->district_id = Input::get('district_id'); $Companionship->update(); return Redirect::back()->with('status', 'Companionship District Removed.'); }
public function postUpdate(Request $Request) { $request = $Request->all(); $Companionship = Companionship::find($request['id']); $NewCompanionship = $Companionship->replicate(); if (isset($request['ht_one_id'])) { $NewCompanionship->htOneId = empty($request['ht_one_id']) ? null : $request['ht_one_id']; } elseif (isset($request['ht_two_id'])) { $NewCompanionship->htTwoId = empty($request['ht_two_id']) ? null : $request['ht_two_id']; } else { return Redirect::back()->with('status', 'Issue updating the companionship.'); } $NewCompanionship->save(); $CompanionshipFamilies = CompanionshipFamily::where('companionship_id', '=', $Companionship->id)->get(); $CompanionshipFamilies->each(function ($CompanionshipFamily) use($NewCompanionship) { $NewWardCompanionshipMember = $CompanionshipFamily->replicate(); $NewWardCompanionshipMember->companionship_id = $NewCompanionship->id; $NewWardCompanionshipMember->save(); }); $Companionship->delete(); return Redirect::back()->with('status', 'Companionship updated.'); }