/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $assistent = Assistent::find($id); if ($this->getRouter()->getCurrentRoute()->getPrefix() == '/api') { // Si no existe ese assistent devolvemos un error. if (!$assistent) { // Se devuelve un array errors con los errores encontrados y cabecera HTTP 404. // En code podríamos indicar un código de error personalizado de nuestra aplicación si lo deseamos. return response()->json(['errors' => array(['code' => 404, 'message' => 'No se encuentra un assistent con ese código.'])], 404); } return response()->json(['status' => 'ok', 'data' => $assistent], 200); } else { if (!Auth::check()) { return Redirect::to('login'); } $assistents = Assistent::where('usuari', '=', $assistent->usuari)->paginate(5); foreach ($assistents as $ass) { $ass->esd = $ass->esdeveniment()->select('titol', 'id')->first(); $votacions = $ass->votacions()->get(); $aux = array(); foreach ($votacions as $vota) { array_push($aux, $vota->votacio()->select('titol', 'id')->first()); } $ass->vota = $aux; } return view('assistentLayouts.show')->with("ass", $assistents)->with("usuari", $assistent->usuari); } }
public function postAssistentsVotacio() { $array = Request::input('ass'); if ($array) { foreach ($array as $ass) { $id = Assistent::where('usuari', "=", $ass)->select('id')->first(); $voAs = VotacioAssistent::where('assistent_id', "=", $id->id)->where('votacio_id', '=', Request::input('id'))->get(); if ($voAs->isEmpty()) { $result = array('assistent_id' => $id->id); $result = array_add($result, 'votacio_id', Request::input('id')); $novaVoAs = VotacioAssistent::create($result); } } } }