jeudi 12 janvier 2023

how Get Multiple value in array with same id laravel & Angular

Here I am trying to get question. At first understand all system we have quiz making system in that we make quizzes but in there a problem if we put a question in any quiz then we creating other quiz the how can we know this particular question is putted in other quizzes or not if yes then which-which. So, here i am trying to get all quizzes title of particular question id. here is controller code

$questions = DB::table('questionbank')
                ->leftJoin('questionbank_quizzes', function($join)
             {
                 $join->on('questionbank_quizzes.questionbank_id','=','questionbank.id');
             })
             ->leftJoin('quizzes', function($join)
             {
                 $join->on('quizzes.id','=','questionbank_quizzes.quize_id');
                      
                      
             })
            //  ->groupBy('questionbank.id')
                ->where('questionbank.subject_id', '=', $request->subject_id)
                ->select('questionbank.id', 'questionbank.subject_id', 'topic_id', 'question_type', 'question', 'questionbank.marks', 'difficulty_level', 'status','quizzes.title')
                ->get(['questionbank.id', 'questionbank.subject_id', 'topic_id', 'question_type', 'question', 'questionbank.marks', 'difficulty_level', 'status', 'quizzes.title']);
     
      return json_encode(array('topics'=>$topics, 'questions'=>$questions, 'subject'=>$subject));

And This is angular code

$scope.subjectChanged = function(selected_number) {
         
        if(selected_number=='')
            selected_number = $scope.subject_id;
        subject_id = selected_number;
        if(subject_id === undefined)
            return;
        route = '';  
        data= {  _method: 'post', 
                '_token':httpPreConfig.getToken(),
                 'subject_id': subject_id
               };

          httpPreConfig.webServiceCallPost(route, data).then(function(result){

            result = result.data;
            $scope.subjectQuestions = [];
            $scope.subject          = result.subject;
            $scope.subjectQuestions = result.questions;
 
            $scope.contentAvailable = true;

           $scope.removeDuplicates();
        
            });
        }

        $scope.removeDuplicates = function(){
           
            if($scope.savedQuestions.length<=0 || $scope.subjectQuestions.length<=0)
                return;

             angular.forEach($scope.savedQuestions,function(value,key){
                    if(value.subject_id != $scope.subjectQuestions[0].subject_id)
                        return;

                    res = httpPreConfig.findIndexInData($scope.subjectQuestions, 'id', value.question_id);
                    if(res >= 0)
                    {
                         $scope.subjectQuestions.splice(res, 1);
                    }
                    
            });
        }

This is blade view

    <div ng-if="subjectQuestions!=''" class="vertical-scroll" >

                                <h4 class="text-success">Questions @ </h4>
                                <table  class="table table-hover">
                                    <th ></th>

                                    <th></th>

                                    <th></th>

                                    <th></th>

                                    <th></th> 

                                    <th></th>    
                                    <tr ng-repeat="question in subjectQuestions | filter: { difficulty_level:difficulty, question_type:question_type, show_in_front_end:show_in_front_end , topic_id:topic, sub_topic_id:sub_topic } | filter: question_model track by $index ">

                                        <td>@</td>
                                        <td title="@" ng-bind-html="trustAsHtml(question.question)">
                                        </td>
                                        <td>  @ </td>
                                        <td>@</td>
                                        <td>@</td>
                                        <td><a ng-click="addQuestion(question, subject);" class="btn btn-primary" ></a>
                                          </td>
                                    </tr>
                                </table>
                                </div>  
                                </div>
                            </div>

Its result is like this

questions:[
0: {id: "4599", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: "MOCK TEST NCERT BOOKS CHEMISTRY 26", topic_id: "120"}
1: {id: "4599", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: "MOCK TEST NCERT BOOKS CHEMISTRY 23", topic_id: "120"}
2: {id: "4600", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: "MOCK TEST NCERT BOOKS CHEMISTRY 26", topic_id: "120"}
3: {id: "4600", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: "MOCK TEST NCERT BOOKS CHEMISTRY 23", topic_id: "120"}
4: {id: "4602", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: "MOCK TEST NCERT BOOKS CHEMISTRY 26", topic_id: "120"}
5: {id: "4602", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: "MOCK TEST NCERT BOOKS CHEMISTRY 23", topic_id: "120"}
6: {id: "4603", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: "MOCK TEST NCERT BOOKS CHEMISTRY 26", topic_id: "120"}
7: {id: "4603", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: "MOCK TEST NCERT BOOKS CHEMISTRY 23", topic_id: "120"}
]

In result you can see with same id title is different but i am stuck here how can i do that. Please help us in this problem. I want result like this..

questions:[
0: {id: "4599", subject_id: "104", topic_id: "120", question_type: "radio",status: "1" subject_id: "104", title: "MOCK TEST NCERT BOOKS CHEMISTRY 26(<br> or ,)MOCK TEST NCERT BOOKS CHEMISTRY 23", topic_id: "120"}
1: {id: "4600", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: ""MOCK TEST NCERT BOOKS CHEMISTRY 26(<br> or ,)MOCK TEST NCERT BOOKS CHEMISTRY 23", topic_id: "120"}
2: {id: "4602", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: ""MOCK TEST NCERT BOOKS CHEMISTRY 26(<br> or ,)MOCK TEST NCERT BOOKS CHEMISTRY 23", topic_id: "120"}
3: {id: "4603", subject_id: "104", topic_id: "120", question_type: "radio",status: "1", subject_id: "104", title: ""MOCK TEST NCERT BOOKS CHEMISTRY 26(<br> or ,)MOCK TEST NCERT BOOKS CHEMISTRY 23", topic_id: "120"}
]


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire