I want to the user doesn't answer twice only one time for the survey so
I used foreach , if , else but i got content for if but else is empty
controller :
public function test(Request $request, Survey $survey)
{
$surveys = Survey::orderBy('id','desc')->limit(1)->get();
$surveys->load('user.questions.answers');
return view('survey.table', compact('surveys'));
}
view
@section('content')
@foreach ($surveys as $survey)
@foreach ($survey->questions as $item)
@foreach ($item->answers as $answer)
@if($answer->user_id == Auth::user()->id)
<div class="card">
<div class="card-content">
<p>
Hi there, there's no survey yet today, Come back later!
</p>
</div>
</div>
@elseif(! $answer->user_id == Auth::user()->id)
<div class="card">
<div class="card-content">
<span class="card-title"> Start taking Survey</span>
<p>
<span class="flow-text"></span> <br/>
</p>
<p>
<br/>Created by: <a href=""></a>
</p>
<div class="divider" style="margin:20px 0px;"></div>
<div id ="circle">
@if($survey->mook_type == 'image')
<img class="fit-picture"
src=""
alt="Grapefruit slice atop a pile of other slices" /><br>
@elseif($survey->mook_type == 'video')
<video class="responsive-video" controls>
<source src="" type="video/mp4">
</video>
@else
<div class="video-wrapper">
<div class="video-container">
<iframe class="youtube-video" width="635" height="340" src="https://www.youtube.com/embed/?enablejsapi=1&version=3&playerapiid=ytplayer" frameborder="0" allowfullscreen></iframe>
</div>
</div>
@endif
<br>
<input type="button" id="btn" class="btn btn-default" value="Next">
</div>
<div id="Create" style="display:none">
{!! Form::open(array('action'=>array('AnswerController@store', $survey->id))) !!}
@forelse ($survey->questions as $key=>$question)
<p class="flow-text">Question - </p>
@if($question->question_type === 'text')
<div class="input-field col s12">
<input id="answer" type="text" name="[answer]">
<label for="answer">Answer</label>
</div>
@elseif($question->question_type === 'textarea')
<div class="input-field col s12">
<textarea id="textarea1" class="materialize-textarea" name="[answer]"></textarea>
<label for="textarea1">Textarea</label>
</div>
@elseif($question->question_type === 'radio')
@foreach($question->option_name as $key=>$value)
<p style="margin:0px; padding:0px;">
<input name="[answer]" type="radio" id="" />
<label for=""></label>
</p>
@endforeach
@elseif($question->question_type === 'checkbox')
@foreach($question->option_name as $key=>$value)
<p style="margin:0px; padding:0px;">
<input type="checkbox" id="something" name="[answer]" />
<label for="something"></label>
</p>
@endforeach
@endif
<div class="divider" style="margin:10px 10px;"></div>
@empty
<span class='flow-text center-align'>Nothing to show</span>
@endforelse
{!! Form::close() !!}
</div>
</div>
</div>
@endif
@endforeach
@endforeach
@endforeach
@endsection
The resultat is an empty else content , is there any ideas to fix else or other ideas to prevent the users answer twice or maybe i have to use forelse and thanks
Aucun commentaire:
Enregistrer un commentaire