/** * Store a newly created resource in storage. * * @return Response */ public function store() { $inputs = $this->checkFamilyMembersSelect(Request::all()); $member = Member::find($inputs['member_id'])->load('family'); if (!$member->family) { $family = Family::create(); $member->update(['family_id' => $family->id]); } $family = Family::find($member->family_id); if ($this->addMembersToFamily($family, $inputs['family_members_id'])) { flash()->success('Members successfully added to family.'); return redirect(url('member/' . $member->id)); } flash()->error('There was an error adding members to family. Please try again.'); return redirect()->back(); }
/** * Give a member a family. * * @param $member * */ protected function storeNewFamily($member) { $family = Family::create(); $member->update(['family_id' => $family->id]); return $member->load('family'); }