public function addFav($id) { if (Auth::check()) { $user_id = Auth::id(); } elseif (Input::has('id')) { $user_id = Input::get('id'); } $aux = Favorito::where('user_id', '=', $user_id)->where('pub_id', '=', $id)->first(); if (is_null($aux) || empty($aux)) { $fav = new Favorito(); $fav->user_id = $user_id; $fav->pub_id = $id; $fav->save(); $response = array('type' => 'success', 'action' => 'add', 'msg' => 'Se ha agregado esta publicación a favoritos.', 'popover' => 'Remover de favoritos', 'url' => URL::to('usuario/publicaciones/remover-favorito/' . $fav->id)); } else { $response = array('type' => 'danger', 'msg' => 'Ya agregaste esta publicación a favoritos.'); } return Response::json($response); }