checkFollow($broker); if ($follow === null) { return $this->store($broker); } else { return $this->destroy($follow); } } public function store(Broker $broker) { Follow::create([ 'broker_id' => $broker->id, 'customer_id' => auth()->id(), ]); return response()->json(['message' => 'Followed successfully.']); } public function destroy(Follow $follow) { $follow->delete(); return response()->json(['message' => 'Unfollowed successfully.']); } protected function checkFollow(Broker $broker) { return Follow::where('broker_id', $broker->id) ->where('customer_id', auth()->id()) ->first(); } }