нужна помощь, как получить данные из базы данных, где та же сумма вопроса меньше 2? Я получаю данные, где идентификатор пользователя не совпадает, но мне нужно также получить там, где вопрос не совпадает. Потому что теперь, когда у меня есть ответ о userId в моей таблице, я могу получить тот же userId в следующем опросе, где разные вопросы, поэтому мне нужно проверить, существуют ли userid и questionId в базе данных
есть идеи, как это сделать?
мой контроллер:
public function viewSurvey($id)
{
$object = DB::table('question')
->where('survey_id', '=', $id)
->where('name', '!=', NULL)
->get();
$teamName = DB::table('survey')->where('surveyId', '=', $id)
->join('team','survey.teamId','=','team.teamId')
->join('company','company.id','=','team.companyID')
->get();
$company = Auth::user()->company;
$date = Survey::where('surveyId', '=', $id)->get();
$teams = Auth::user()->teams;
$checkUserTeam = DB::table('teammembersall')
->where('UserId', '=', Auth::user()->id)
->get();
$members = Survey::where('surveyId', '=', $id)
->join('team', 'team.teamId', '=', 'survey.teamId')
->join('teammembersall', 'teammembersall.TeamId', '=', 'team.TeamId')
->join('users', 'users.id', '=', 'teammembersall.UserId')
->select('users.*')
->whereNotExists(function ($query) {
$query->select(DB::raw(1))
->from('answer')
->whereRaw('answer.answerAboutUserId = users.id')
->andWhere('answer.questionId', '<', 2);
})
->get();
$questions = DB::table('answer')->get();
return view('survey_details', ['object' => $object, 'date' => $date, 'teams' => $teams, 'members' => $members, 'questions' => $questions, 'checkUserTeam' => $checkUserTeam, 'teamName' => $teamName, 'company' => $company ]);
}
мой взгляд:
<html>
<head>
<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="">
<img src={{url('')}} width="100%" height="auto" alt=""/>
<div class="" style="display:none">
@foreach($teamName as $tname)
<h4>Team name:</h4>
<p>{{ $tname->nameCompany}}</p>
@endforeach
{{ $company->nameCompany }}
</div>
</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( $tname->nameCompany == $company->nameCompany )
<div class="survey-theme">
@foreach($members as $memb)
@if($memb->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="{{ $memb->name}}" readonly></h2>
<input style="border:none;background:none;display:none" name="surveyUserDataId" value="{{ $memb->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>It's 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>