/** * Links bank with apartment * @param $id */ public function linkBank($id) { $apartment = Auth::user()->profile->defaultApartment; $bank = Bank::findorFail($id); if ($bank->apartment->contains($apartment)) { $bank->apartment()->detach($apartment); // return redirect()->route('bank.show', [$bank->id]) return redirect()->back()->withMessage('Bank Un-Linked from your List.')->withStatus('danger'); } else { // $bank->apartment()->sync([$apartment]); $bank->apartment()->attach($apartment); // return redirect()->route('bank.show', [$bank->id]) return redirect()->back()->withMessage('Bank has been linked to the Apartment Accounts !')->withStatus('success'); } }