How can I go through a condition with laravel blade

0

Hello very good afternoon ... I am doing a survey system and enter the part where I have to show the results of the survey ...

I have a table of answers where there are 10 columns with the name answer1, answer2, answer3, .... up, answer10. What I do is go through the columns that have a record and count them to know how many answers a question had and here is the problem.

    @foreach($votos as $voto)
    @if($voto->idpregunta == $pregunta_id)
        @if(Auth::user()->id == $voto->user_id)
            <?php $habilitado = "no" ?>
        @endif
        @if(!empty($voto->respuesta1))
            <?php $count+=1; $texto="$voto->respuesta1";?>
        @endif
    @endif
@endforeach

As seen in the code if I want to do for the 10 answers I have to do 10 if to count them, as well as 10 variables to save them and the code will be very ugly .. in case it is already ugly ..

My question is .. how can I do a tour so that I do not have to do 10 times the conditioner. What I need is a little help to start ...

In my controller there is not much to show because I only send data ...

public function create()
{
    //
    $preguntas = Pregunta::all();
    $votos = Respuesta::all();
    $respuesta = new Respuesta;
    return view('user.respuesta.respuesta', compact('preguntas', 'respuesta', 'votos'));
}

Any help I appreciate .. I would like to be able to do the previous code in the controller but I do not know how to do it because I am a newbie

    
asked by Hernan Chaparro 27.09.2018 в 20:40
source

0 answers