我有一个问题,正在做一些调查应用程序,但遇到了问题。我正在获取表单中的团队调查问题和用户。比如示例团队有 10 名成员。并进行了调查。因此,需要针对每个用户回答相同的调查问题。我正在以如下形式获取:
UserId , UserName Question1 Question2 Question3 NextUserId , NExtUserName Question1 Question2 Question3因此,如果数据库中已经存在关于该用户的问题的答案,那么我需要如何使用用户名和问题隐藏 div,或者只是问题。我的意思是,如果我在调查中回答了关于第一个用户的问题,那么下次当我打开同一个调查时,如果我已经回答了关于他的问题,我不应该再看到相同的用户和有关它的问题。
我放置答案和用户 ID 的数据库表如下所示:
AnswerAboutUserId -已回答的用户 ID MemberId -回答问题的人 Answer AnswerId QuestionaName
我怎样才能做到这一点?
在我的控制器下方并查看
控制器:
public function viewSurvey($id)
{
$object = DB::table('question')->where('survey_id' , '=', $id)->get();
$date = Survey::where('surveyId' , '=', $id)->get();
$teams = Auth::user()->teams;
$survey = Survey::where('surveyId' , '=', $id)
->join('team','team.teamId', '=', 'survey.teamId')
->join('teammembersall','teammembersall.TeamId', '=', 'team.TeamId')
->join('users','users.id', '=', 'teammembersall.UserId')
->select('users.*')
->get();
$questions = DB::table('answer')->get();
return view('survey_details', ['object' => $object, 'date' => $date, 'teams' => $teams, 'survey' => $survey, 'questions' => $questions]);
}
这是我的视图刀片:
<html>
<head>
<title>Dynamically Add or Remove input fields in PHP with JQuery</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
<hr>
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-8">
<br>
<div style="display:none">
{{ $dates = date('Y-m-d H:i:s') }}
</div>
<div class="container-survey-logo">
<img src={{url('/img/survey-banner.jpg')}} width="100%" height="auto" alt=""/>
<div class="text-block-survey-date">
@foreach($date as $dat)
<h4>End date:</h4>
<p>{{ $dat->ended_at}}</p>
@endforeach
</div>
</div>
<div style="display:none;">
@foreach($questions as $quest)
<p>{{ $quest->answerAboutUserId}}</p>
@endforeach
</div>
@if($dat->ended_at > $dates )
@if ($teams = Auth::user())
<div class="survey-theme">
@foreach($survey as $surv)
@if($surv->id != Auth::user()->id)
<form action="/confirmSurveyAnswers" method="post">
{{csrf_field()}}
<br>
<div class="well well-lg">
<h5>
Questions about member:
<h2><input style="border:none;background:none" name="surveyName" value="{{ $surv->name}}" readonly></h2>
<input style="border:none;background:none;display:none" name="surveyUserDataId" value="{{ $surv->id}}" readonly>
</h5>
<br>
@foreach($object as $object_each)
<input style="font-size:20px;" type="text" class="form-control" id="exampleInputAnswer" name="questionName[{{$object_each->id}}]" value="{!! $object_each->name !!}" readonly>
<div class="survey-questions">
<label class="radio-inline-text">
Not agree
</label>
<label class="radio-inline">
<input type="checkbox" value="1" name="QuestionsAnswers[{{$object_each->id}}]" >1
</label>
<label class="radio-inline">
<input type="checkbox" value="2" name="QuestionsAnswers[{{$object_each->id}}]" >2
</label>
<label class="radio-inline">
<input type="checkbox" value="3" name="QuestionsAnswers[{{$object_each->id}}]" >3
</label>
<label class="radio-inline">
<input type="checkbox" value="4" name="QuestionsAnswers[{{$object_each->id}}]" >4
</label>
<label class="radio-inline">
<input type="checkbox" value="5" name="QuestionsAnswers[{{$object_each->id}}]" >5
</label>
<label class="radio-inline">
<input type="checkbox" value="6" name="QuestionsAnswers[{{$object_each->id}}]" >6
</label>
<label class="radio-inline">
<input type="checkbox" value="7" name="QuestionsAnswers[{{$object_each->id}}]" >7
</label>
<label class="radio-inline">
<input type="checkbox" value="8" name="QuestionsAnswers[{{$object_each->id}}]" >8
</label>
<label class="radio-inline">
<input type="checkbox" value="9" name="QuestionsAnswers[{{$object_each->id}}]" >9
</label>
<label class="radio-inline">
<input type="checkbox" value="10" name="QuestionsAnswers[{{$object_each->id}}]" >10
</label>
<label class="radio-inline-text">
Fully agree
</label>
</div>
@endforeach
<div class="im-done-button">
<button type="submit" class="btn btn-primary">I'm Done</button>
</div>
</div>
@endif
</form>
@endforeach
<Br>
@include('layouts.errors')
</div>
@else <h1>This is not your team survey</h1> @endif
@else <h1>This survey ended</h1> @endif
</div>
<div class="col-md-2">
</div>
</div>
<hr>
</div>
</body>
</html>