public function rate($id) { $wbbUId = \Input::get('wbbUId'); $i = explode('_', explode(' ', \Input::get('clickedOn'))[0])[1]; $c = Rating::where('downloadId', $id)->where('WbbUId', $wbbUId)->count(); if ($c > 0) { Rating::where('downloadId', $id)->where('WbbUId', $wbbUId)->update(array('value' => $i)); } else { Rating::create(array('value' => $i, 'downloadId' => $id, 'WbbUId' => $wbbUId)); } return response(array('avg' => intval(round(Rating::getAvg($id))))); }