Skip to content

Instantly share code, notes, and snippets.

@Cyberiaaxis
Created March 26, 2018 17:10
Show Gist options
  • Save Cyberiaaxis/f99dc409db34441f8cd2e742aaa0c18d to your computer and use it in GitHub Desktop.
Save Cyberiaaxis/f99dc409db34441f8cd2e742aaa0c18d to your computer and use it in GitHub Desktop.
public function index(Request $request)
{
$questionsIds = Question::whereHas('questionMapper', function ($q) use ($request) {
$q->where('category_id', $request->jcategory_id);
$q->where('designation_id', $request->designation_id);
$q->where('department_id', $request->department_id);
})->with('questionMapper.questionCategory')->inRandomOrder()->get();
// $userQuestionCollection = [];
$userQuestion = $questionsIds->each(function ($item, $key){
$userQuestionStack = UserQuestion::where('user_id',Auth::user()->id)->whereNull('questionattempted')->get();
//total question count
$userQuestionCount = $userQuestionStack->count();
//category wise question count
$questionCategoryCount = $userQuestionStack->where('questioncategory_id', $item->questionMapper->questioncategory_id)->count();
$postwiseCount =
Designation::find($item->questionMapper->designation_id);
// dd($postwiseCount->qcount);
//as per post wise question set
$postCategoryCount = $postwiseCount[$item->questionMapper->questionCategory->questioncatname];
if($questionCategoryCount <= $postCategoryCount || $userQuestionCount <= $postwiseCount->qcount){
return new UserQuestion([
'question_id' => $item->questionMapper->question_id,
'questioncategory_id' => $item->questionMapper->questionCategory->id,
]);
// print_r($userQuestionCollection);
}
// dd($userQuestionCollection);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment