public function respostesAssistents($idVotacio, $idAssistent)
 {
     $assistent = Assistent::find($idAssistent);
     $respostes = Resposta::where('usuari_id', '=', $assistent->usuari)->where('votacio_id', '=', $idVotacio)->get();
     $votacio = Votacio::find($idVotacio);
     //$result = array('votacio'=>$votacio->titol);
     //$result = array_add($result,'usuari',$assistent->usuari);
     //$i = 1;
     //$pregResp = Array();
     if ($respostes->count() == $votacio->preguntes()->count()) {
         $total = true;
     } else {
         $total = false;
     }
     foreach ($respostes as $res) {
         $pregunta = Pregunta::find($res->pregunta_id);
         $res->pregunta = $pregunta->titol;
         //$pregResp = array_add($pregResp,'pregunta'.$i,$res->resposta);
         //$pregResp = array_add($pregResp,'resposta'.$i,$res->resposta);
         //++$i;
     }
     //$result = array_add($result,'pregResp',$pregResp);
     return view('respostaLayouts.show')->with("result", $respostes)->with("votacio", $votacio->titol)->with("usuari", $assistent->usuari)->with("total", $total)->with("idAssistent", $idAssistent)->with("idVotacio", $idVotacio)->with("idEsdeveniment", $assistent->esdeveniment_id);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($idVotacio, $idPregunta)
 {
     // Comprobamos si la votacio que nos están pasando existe o no.
     $votacio = Votacio::find($idVotacio);
     // Si no existe ese esdevenimentd evolvemos un error.
     if (!$votacio) {
         // 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 una votacio con ese código.'])], 404);
     }
     // El votacio existe entonces buscamos el pregunta que queremos borrar asociado a ese votacio.
     $pregunta = $votacio->preguntes()->find($idPregunta);
     // Si no existe ese pregunta devolvemos un error.
     if (!$pregunta) {
         // 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 una pregunta con ese código asociado a ese esdeveniment.'])], 404);
     }
     // Procedemos por lo tanto a eliminar el assistent.
     $pregunta->delete();
     // Se usa el código 204 No Content – [Sin Contenido] Respuesta a una petición exitosa que no devuelve un body (como una petición DELETE)
     // Este código 204 no devuelve body así que si queremos que se vea el mensaje tendríamos que usar un código de respuesta HTTP 200.
     return response()->json(['code' => 204, 'message' => 'Se ha eliminado la pregunta correctamente.'], 204);
 }
 public function assistents($id)
 {
     $votacio = Votacio::find($id);
     $assistents = $votacio->assistents()->select('id')->paginate(5);
     foreach ($assistents as $ass) {
         //$ass = array_add($ass, 'result', VotacioAssistent::find($ass->id)->assistent()->get());
         $ass->ass = VotacioAssistent::find($ass->id)->assistent()->first();
     }
     $assistents->id = $id;
     return view('assistentLayouts.index2')->with("ass", $assistents);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($idEsdeveniment, $idAssistent)
 {
     $assistent = Assistent::find($idAssistent);
     $votaAss = $assistent->votacions()->select('votacio_id')->get();
     $a = collect([]);
     $b = collect([]);
     foreach ($votaAss as $v) {
         $a->push($v->votacio_id);
     }
     $votacions = Esdeveniment::find($assistent->esdeveniment_id)->votacions()->get();
     foreach ($votacions as $v) {
         $b->push($v->id);
     }
     $diff = $b->diff($a);
     $arrayVota = [];
     $i = 1;
     foreach ($diff as $vota) {
         $votac = Votacio::find($vota);
         $arrayVota = array_add($arrayVota, $i, $votac->titol);
         ++$i;
     }
     return view('assistentLayouts.edit')->with("ass", $assistent)->with("vota", $arrayVota);
 }
 public function postAssistentVotacio()
 {
     $array = Request::input('vota');
     if ($array) {
         foreach ($array as $vota) {
             $id = Votacio::where('titol', "=", $vota)->select('id')->first();
             $voAs = VotacioAssistent::where('assistent_id', "=", Request::input('id'))->where('votacio_id', '=', $id->id)->get();
             if ($voAs->isEmpty()) {
                 $result = array('assistent_id' => Request::input('id'));
                 $result = array_add($result, 'votacio_id', $id->id);
                 $novaVoAs = VotacioAssistent::create($result);
             }
         }
     }
 }