david001

david001

Member Since 4 Years Ago

Experience Points
11,580
Total
Experience

3,420 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
3
Lessons
Completed
Best Reply Awards
1
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 3
11,580 XP
Sep
18
3 weeks ago
Activity icon

Started a new conversation How To Query This

Hi in my app

results table

i have id/user_id/question_id/quiz_id/answer_id

in questions table id/quiz_id/name

in answers table id/question_id/answer/is_correct

quiz table id/name

The results table store all the result of played quiz. it store id of user,question id and user choosen answer which may be correct or wrong.

answers table contain four answer with one correct option(is_correct) for particular question.

Now i want to find out how many answers were given correct and how many were given wrong.

in my controller

Result::where('quiz_id',$quizId)->where('user_id',$userId)->get();


in view

<?php $sum=0;?>
@foreach($results as $key =>$result)
                       <tr>
                        <td>{{$key+1}}</td>
                        <td>{{$result->question->name}}</td>
                        <td>{{$result->answer->answer}}</td>
                        @if($result->answer->is_correct==1)
                        <td>
                          <?php $sum = $sum+$key; 
                          echo $sum;?>
                          Correct

                        </td>
                        @else
                        <td>Wrong</td>
                        @endif



i tried to count correct answer in view as well but i can't get the total correct answer given by user.
Any help is highly appreciated
Sep
17
3 weeks ago
Activity icon

Replied to How To Query GroupBy

to list users along with quiz name for exam john may be assigned to quiz example , quiz1, and quiz2

so output should be

name quiz

John quiz1,quiz2

Activity icon

Started a new conversation How To Query GroupBy

I have users,quizzes and quiz_users table.

users table have id/name/email/password/timestamps

quizzes table have id/name/description/timestamps

quiz_users table have id/user_id/quiz_id

so i have 2 model

User.php and Quiz.php and quiz_users is pivot table, it contains the particular quiz assigned to particular user, user_id and quiz_id

Now i want to fetch all users groupBy quiz_id, how can i query it? i tried in this way

User::has('quizees')->groupBy('user_id')->paginate(10); 

but it has error. Any help is highly appreciated.

Sep
09
1 month ago
Activity icon

Replied to How To Pass Data (emit)

Thanks for idea

Sep
08
1 month ago
Activity icon

Started a new conversation How To Pass Data (emit)

Hi i have one question which may be sounds stupid, actually i haven't made any components just doing in same file. Here i'm making a Quiz app. in the last part in postUserChoice() method i want to pass current user choice question and user choosen answer(choice). I can easily pass question because postUserChoice is with in the question div but

  • where i have loop the answer finish before the next() method(Next Button) div.

    
    <div v-for="(question, index) in questions">
                                <!-- Hide all questions, show only the one with index === to current question index -->
                                <div v-show="index === questionIndex">
                                    <strong>{{ question.name }}</strong>
                                    <ol>
                                      
                                        <li v-for="choice in question.answers">
                                            <label>
                                                
                                    <input type="radio"
                                    :value="choice.is_correct == true ? true : choice.answer"
                                    :name="index"
                                    v-model="userResponses[index]"
                                    @click="choices(question.id,choice.id);answeremit(choice)"> 
                                    {{choice.answer}}
                                    
                                            </label>
                                        </li>
                                    </ol>
                                    <!-- The two navigation buttons -->
                                    <!-- Note: prev is hidden on first question -->
                                    <div class="pull-right">
                                        <button class="btn btn-success" v-if="questionIndex > 0" @click="prev">
                                            <span class="glyphicon glyphicon-arrow-left"></span>
                                            prev
                                        </button>
                                        <button class="btn btn-success" 
                                        @click="next(); postUserChoice(question,choice)">
                                            <span class="glyphicon glyphicon-arrow-right"></span>
                                            next
                                        </button>
                                    </div>
    
                                </div>
                                  
                            </div>
    
    

    This is how i want to get current question and user choosen answer. But how can i get choice(answer user choosed)

    
    postUserChoice(question,choice){
                    this.answerQuestion.push({
                        answer:choice,
                        question:question
                    })
                }
    

    This is the error

    
    Property or method "choice" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property
    
  • Sep
    05
    1 month ago
    Activity icon

    Replied to Vue Js Time Countdown

    Any help please..

    Sep
    04
    1 month ago
    Activity icon

    Started a new conversation Vue Js Time Countdown

    Hi , i'm new to vue js and want to make minute and second timer and want to alert when time reaches zero. This is so far i have done.

    
    <template>
       {{ countDown }} minutes ramaning
    </template>
    
    <script>
        export default {
            data() {
                return {
                    countDown : 10
                }
            },
            method: {
                countDownTimer() {
                    if(this.countDown > 0) {
                        setTimeout(() => {
                            this.countDown -= 1
                            this.countDownTimer()
                        }, 60000)
                    }
                }
            }
            created: {
               this.countDownTimer()
            }
        }
    </script>
    

    i want to show output as 10 min 59 sec remaining... and decrementing sec and min.. Please help to display minute and second

    Aug
    30
    1 month ago
    Activity icon

    Started a new conversation [Vue Warn]: Error In Render: "TypeError: Cannot Read Property 'length' Of Undefined

    Hi, I am making a simple quiz with laravel and vue js but i got error app.js:39679 [Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined

    Anybody please help me to solve this error following is my Quizomponent.vue.

    
    <template>
        <div class='row'> 
        <div class='row'> 
          <router-link :to="{ name: 'CreateQuiz' }" class="btn btn-default">Create Quiz</router-link> 
          <br />
        </div>
        <div class="col-md-6 mb-6">    
          <div clss="row">
            <div class="col-md-12 mb-12 card indigo form-white">
              <h2 class="text-center default-text py-3">Quizzes</h2>
              <ul class="list-group">
                <div v-for="(question, index) in quiz.questions">
                  <div v-show="index === questionIndex">
                    <li class="list-group-item"><h2>{{ question.name }}</h2></li>
                    <li class="list-group-item" v-for="response in question.answers">
                      <input type="radio" 
                         v-bind:value="response.is_correct" 
                         v-bind:name="index" 
                         v-model="userResponses[index]"> {{response.answer}}
                    </li>
                    <li class="list-group-item" style="padding:30px;">
                      <button  v-if="questionIndex > 0" v-on:click="prev" class="btn btn-danger btn-xs pull-right" style="margin-top: -10px;">Previos</button>
                      <button v-on:click="next" class="btn btn-danger btn-xs pull-right" style="margin-top: -10px;">Next</button>
                    </li>
                  </div>
                </div>
                
                
                <div v-show="questionIndex === quiz.questions.length">
                  <li class="list-group-item">
                    <h2>
                      Quiz finished
                    </h2>
                    <p>
                      Total score: {{ score() }} / {{ quiz.questions.length }}
                    </p>
                  </li>
                </div>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </template>
    
    
    <script>
    
        export default {
        
            data() {
                return {
                    list: '',
            quiz: [],
            questionIndex: 0,
            userResponses: [],
                };
            },
            
            created() {
                this.fetchQuizList();
            },
            
            methods: {
                fetchQuizList() {
                    axios.get('question').then((res) => {
              this.quiz = res.data;
              this.userResponses = Array(this.quiz.questions.length).fill(false)
                    });
                },
          
          next: function() {
            this.questionIndex++;
          },
          
          prev: function() {
            this.questionIndex--;
          },
          
          score: function() {
            return this.userResponses.filter(function(val) { return val }).length;
          }
        }
    
        }
    </script>
    
    Aug
    29
    1 month ago
    Activity icon

    Replied to Laravel Vue Save Quiz Result In Database

    when user click the next button i want to save current question, user chosen answer and correct answer in db.

    when user click the previous button and want to update his choice, changes should also be updated in db

    Activity icon

    Started a new conversation Laravel Vue Save Quiz Result In Database

    Hello developers, i'm problem here. Actually i am implementing a simple quiz with laravel and vue js and want to save result of user choices in db. i want to save my final result to results table which has an attribute as

    id,question,given_answer,true_answer,created_at,updated_at

    what i want to achieve?

    1. when user click the next button i want to save current question, user chosen answer and correct answer in db.
    2. when user click the previous button and want to update his choice, changes should also be updated in db.

    This is my Quizcomponent.vue file

    
    
    <template>
        <div class="container">
            <div class="row justify-content-center">
    {{questionAnswer}}
      <div v-for="(question, index) in questions":key="question.id">
        <div v-show="index === questionIndex">
          <h2>{{ question.name }}</h2>
          <ol>
            <li v-for="answer in question.answers":key="answer.id">
              <label :for="'answer-'+answer.id">
                 <input type="radio" 
                       name="answer"
                       id="'answer-'+answer.id" @click="choose(question,answer)" 
                       >
              </label>{{answer.choice}}
            </li>
          </ol>
          <button v-if="questionIndex > 0" v-on:click="prev">
            prev
          </button>
          <button v-if="showNext" v-on:click="next(question)">
            next
          </button>
        </div>
      </div>
    
      <div v-show="questionIndex === questions.length">
        <h2>
          Quiz finished
        </h2>
        <p>
        </p>
      </div>
    
    
    
    
            </div>
        </div>
    </template>
    
    <script>
        export default {
            data:function(){
                return {
                    showNext:'',
                    questionAnswer:[],
                    answerChosen: null,
                     questionIndex: 0,
    
                        questions: []
    
                    }
            },
            mounted() {
    //here i fetched list of questions with questions options
                console.log('Component mounted.')
                var app=this;
                axios.get('/question')
                    .then(function (resp) {
                        console.log(resp)
                        app.questions = resp.data; 
                        console.log(resp)
    
                    })
            },
                methods: {
                  next: function(question) {
        //when user click next button i want to save result in db
    
                    this.questionIndex++;
                 //   this.questionAnswer.push({
                       //     question:question.id,
                           // answer:answers.choice
                      //  })
    
                  },
                  prev: function() {
    //when user click prev button and update his answer want to update in db
                    this.questionIndex--;
                  },
                  choose:function(question,answer){
                      
                    this.showNext=true
    
    
                  },
                  score: function() {
                   
                  }
        }
        }
    </script>
    

    This is questions with options and correct answer fetched from db and push in questions[]

    
    [
    {
    id: 1,
    name: "What is the value of 2+2?",
    created_at: "-0001-11-30 00:00:00",
    updated_at: "-0001-11-30 00:00:00",
    answers: [
    {
    id: 1,
    question_id: 1,
    choice: "2",
    correct: "false"
    },
    {
    id: 2,
    question_id: 1,
    choice: "4",
    correct: "true"
    },
    {
    id: 5,
    question_id: 1,
    choice: "3",
    correct: "false"
    },
    {
    id: 6,
    question_id: 1,
    choice: "5",
    correct: "false"
    }
    ]
    },
    {
    id: 2,
    name: "what is PHP?",
    created_at: "-0001-11-30 00:00:00",
    updated_at: "-0001-11-30 00:00:00",
    answers: [
    {
    id: 3,
    question_id: 2,
    choice: "Hypertext Preprocessor",
    correct: "true"
    },
    {
    id: 4,
    question_id: 2,
    choice: "personal page",
    correct: "false"
    }
    ]
    },
    {
    id: 3,
    name: "what is js",
    created_at: "-0001-11-30 00:00:00",
    updated_at: "-0001-11-30 00:00:00",
    answers: [
    {
    id: 7,
    question_id: 3,
    choice: "javascript",
    correct: "true"
    },
    {
    id: 8,
    question_id: 3,
    choice: "java server",
    correct: "false"
    }
    ]
    }
    ]
    
    Aug
    21
    1 month ago
    Activity icon

    Replied to Remove From Session

    Hi can you help me with the code. Thanks for reply

    Activity icon

    Started a new conversation Remove From Session

    Hi guys, i have a problem in remove the items from session when user click the remove item button from the session. Let me divide my problem in two parts

    1First: There are certain items in cart, if i click remove item button, items are removed from session based on index value sent by ajax request. In this case i have not refresh the page that display the products.

    2 Second. There are certain items in cart, if i click remove item button for any product, the product is now removed from session and their are remaining products. Now if i refresh web page, their index value decreased by one since i already removed one item from session. Now if i click remove button, some of the product are not removed. Can anybody suggest me what actually happening here. Thanks

    Part of vue code

    
     <div class="card-body" v-for="(list,index) in cart">
                            <img :src="list.image" width="80">
                           index:{{index}} {{list.name}}
                          
    
                            <button @click="remove(index)">X</button>
                 </div>
    
    
                remove(index){
                    axios.get('/delete',{
    
                         params: {
                             index: index,
                        }
    
                    }).then((response)=>{
                    //this.cart123.push(product)
    
                    });
                }
    

    This is the method to remove Item from session

    public function removeFromSession(Request $request){
          
            $index = $request->index;//index value of item sent from view when user clicks remove item
    
            $request->session()->forget('product.' . $index);
        
    
          }
    

    Data stored in session as

    
    [
    {
    id: 2,
    name: "Marlene Reichert",
    description: "Debitis asperiores sed sit assumenda unde quo natus. Consequatur est labore tenetur quae. Eius distinctio ea omnis aspernatur porro earum quae.",
    category_id: 3,
    price: 76,
    image: "http://loremflickr.com/400/300?random=71",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 4,
    name: "Bart Kuvalis",
    description: "Eaque iure excepturi nisi est dolore sapiente in sequi. Minus odit ab et id consectetur sunt.",
    category_id: 9,
    price: 162,
    image: "http://loremflickr.com/400/300?random=40",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 6,
    name: "Kaylin Emard",
    description: "Et aperiam omnis nam iure id non fugiat. Excepturi voluptatem ipsam magnam. Esse asperiores ducimus enim et.",
    category_id: 8,
    price: 14,
    image: "http://loremflickr.com/400/300?random=17",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    }
    ]
    
    Aug
    16
    1 month ago
    Activity icon

    Replied to Remove From Session Laravel And Vue

    when i do not refresh the page, the product are deleted on clicking delete button from session. but when i click delete button for one product and refresh the page, and try to remove another product by clicking the delete button, product is not deleted

    
    public function deleteProduct(Request $request){
           // dd($request->id);
            $id = $request->id;
            return $request->session()->forget('product.' . $id);
    }
    

    Does index value changes with that of session data when i refresh the page?

    Aug
    15
    1 month ago
    Activity icon

    Replied to Laravel Vue Js

    @tykus , when i do not refresh the page, the product are deleted on clicking delete button from session. but when i click delete button for one product and refresh the page, and try to remove another product by clicking the delete button, product is not deleted

    
    public function deleteProduct(Request $request){
           // dd($request->id);
            $id = $request->id;
            return $request->session()->forget('product.' . $id);
    }
    

    Does index value changes with that of session data when i refresh the page?

    Activity icon

    Replied to Laravel Vue Js

    I can see the products now, but only problem still is all items are removed one by one, but still two items are not removed, especially when i refresh the view page

    Activity icon

    Replied to Laravel Vue Js

    Thanks @tykus , At first,before removing item the data in session format was as below

    
    [
    {
    id: 1,
    name: "Keyshawn McDermott Sr.",
    description: "Error aut quia id dolorem est aut doloribus nesciunt. Quod nihil tenetur ea id voluptas molestias id. Debitis amet dolor est fugiat sed autem.",
    category_id: 1,
    price: 59,
    image: "http://loremflickr.com/400/300?random=36",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 3,
    name: "Ms. Clarissa Olson Jr.",
    description: "Totam eius qui ut impedit nobis excepturi. Enim consequatur inventore dolorem laboriosam sequi dolore harum quibusdam. Doloribus ad tenetur tenetur et ut.",
    category_id: 6,
    price: 111,
    image: "http://loremflickr.com/400/300?random=75",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 4,
    name: "Bart Kuvalis",
    description: "Eaque iure excepturi nisi est dolore sapiente in sequi. Minus odit ab et id consectetur sunt.",
    category_id: 9,
    price: 162,
    image: "http://loremflickr.com/400/300?random=40",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    }
    ]
    

    i used this

    
            $id = $request->id;
            return $request->session()->forget('product.' . $id);
    

    to remove product form session. it removed only item. and once i looked my session data ,now it turns with following, giving index value as well and unable to show in page and remove.

    
    {
    2: {
    id: 4,
    name: "Bart Kuvalis",
    description: "Eaque iure excepturi nisi est dolore sapiente in sequi. Minus odit ab et id consectetur sunt.",
    category_id: 9,
    price: 162,
    image: "http://loremflickr.com/400/300?random=40",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    3: {
    id: 6,
    name: "Kaylin Emard",
    description: "Et aperiam omnis nam iure id non fugiat. Excepturi voluptatem ipsam magnam. Esse asperiores ducimus enim et.",
    category_id: 8,
    price: 14,
    image: "http://loremflickr.com/400/300?random=17",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    }
    }
    
    Activity icon

    Replied to Remove From Session Laravel And Vue

    @tykus hi i have updated, i want to delete one product at a time based on button clicked. if user clicked remove button for item with index 0, item with index 0 should be removed, similarly if user clicked remove button for item with index1, item with index 1 should be removed

    Activity icon

    Started a new conversation Remove From Session Laravel And Vue

    Hi, i'm not able to delete data from the session. There are some data in the session . Now i want to remove one by one based on index value sent form ajax request.

    
    //method to store in session, with ajax request
        public function store(Request $request) {
           
             $request->session()->push('product',json_decode($request->product));
             return session('product');
            
        }
    //method to get data from session
        public function getFromSession(Request $request){
            
            $product = $request->session()->get('product');
    
            return $product;
           
        }
    //delete method
        public function deleteProduct(Request $request){
           // dd($request->id);
       $request->id is the index value which starts from zero sent from view when user click remove button using 
         ajax request
     }
    

    Route for delete

    
    Route::get('/delete','[email protected]');
    

    in view

    
    //part of code
    //getting data from session and looping 
          <div class="card-body" v-for="(list,index) in cart">
                            <img :src="list.image" width="80">
                           index:{{index}} {{list.name}}
                          
    
                            <button @click="del(index)">X</button>
                 </div>
    
    //....
                remove(index){
                    axios.get('/delete',{
    
                         params: {
                            id: index,
                        }
    
                    }).then((response)=>{
                    //this.cart123.push(product)
    
                    });
                }
    

    Just what to know how to delete product based on delete from session and remove from page as well. Any help would be greatly appreciated

    data in session: on dd($products) }

    array:3 [▼
      0 => {#225 ▼
        +"id": 3
        +"name": "Ms. Clarissa Olson Jr."
        +"description": "Totam eius qui ut impedit nobis excepturi. Enim consequatur inventore dolorem laboriosam sequi dolore harum quibusdam. Doloribus ad tenetur tenetur et ut."
        +"category_id": 6
        +"price": 111
        +"image": "http://loremflickr.com/400/300?random=75"
        +"created_at": "2019-07-16 10:12:27"
        +"updated_at": "2019-07-16 10:12:27"
        +"qty": 1
      }
      1 => {#226 ▼
        +"id": 6
        +"name": "Kaylin Emard"
        +"description": "Et aperiam omnis nam iure id non fugiat. Excepturi voluptatem ipsam magnam. Esse asperiores ducimus enim et."
        +"category_id": 8
        +"price": 14
        +"image": "http://loremflickr.com/400/300?random=17"
        +"created_at": "2019-07-16 10:12:27"
        +"updated_at": "2019-07-16 10:12:27"
        +"qty": 1
      }
      2 => {#227 ▼
        +"id": 5
        +"name": "Prof. Iliana Mohr"
        +"description": "Autem sequi esse laudantium ut ut explicabo enim. Corporis cupiditate dolorum et ratione sequi architecto. Vitae enim ex hic nihil."
        +"category_id": 2
        +"price": 207
        +"image": "http://loremflickr.com/400/300?random=99"
        +"created_at": "2019-07-16 10:12:27"
        +"updated_at": "2019-07-16 10:12:27"
        +"qty": 1
      }
    ]
                }
    
    Activity icon

    Started a new conversation Laravel Vue Js

    Hi, i have some data in session, i want to show those data when page is mounted , but not data from session is displayed in my page.

    
        public function getProduct(Request $request){
            $product = session()->get('product');
            return $product;
          
        }
    

    this gives

    
    {
    1: {
    name: "Keyshawn McDermott Sr.",
    quantity: 1,
    price: 59,
    image: "http://loremflickr.com/400/300?random=36"
    },
    2: {
    name: "Marlene Reichert",
    quantity: 1,
    price: 76,
    image: "http://loremflickr.com/400/300?random=71"
    }
    }
    

    on dd($products) i got

    
    array:2 [▼
      2 => array:4 [▼
        "name" => "Marlene Reichert"
        "quantity" => 1
        "price" => 76
        "image" => "http://loremflickr.com/400/300?random=71"
      ]
      1 => array:4 [▼
        "name" => "Keyshawn McDermott Sr."
        "quantity" => 1
        "price" => 59
        "image" => "http://loremflickr.com/400/300?random=36"
      ]
    ]
    

    productComponent.vue

    <template>
    <div>
    <p v-for="product in products">
    
    {{product.name}}//nothing is displayed here
    </p>
    </div>
    
    </template>
    
    
    <script>
        export default {
    
            data:function(){
                return {
                    products:[],
                   
    
                }
    
            },
            methods:{
    
    
      
            },
                computed: {
                    
      
            },
              Total() {
                 
    
            },
                mounted() {
                   
    
                        axios.get('/session-products')
    
                        .then(function (resp) {
                            console.log(resp)
                          //  alert(resp.data)
                            app.products = resp.data
                            
                        })
    
                }
            }
    </script>
    
    Aug
    07
    2 months ago
    Activity icon

    Replied to How To Delete Item From Session

    data is not removed from session

    
      $id = $request->productId;
            
        $products = collect($request->session()->get('product'));
    
    $products = $products->reject(function($item)  use($id) {
            return $item->id ?? $id == $id;
    });
     session()->put('product',$products);
    
    Aug
    06
    2 months ago
    Activity icon

    Replied to How To Delete Item From Session

    i got this error : {message: "Cannot use object of type stdClass as array",}

    so i is changed it to

            $id = $request->productId;
            
          $products = collect($request->session()->get('product'));
    
          $products = $products->reject(function($item)  use($id) {
            return $item->id?? $id == $id;//here
    });
    

    Now i didn't got any error, but still that item is in session, it is not removed from session even i clicked delete button for that item from my view page. do i need to update session?

    Activity icon

    Replied to How To Delete Item From Session

    @snapey

    when i clicked delete button this is the error i can see in network tab

    message: "Property [id] does not exist on this collection instance."
    

    This are two methods

    
    store in session
        public function StoreInCart(Request $request) {
            //dd(($request->product));
             $request->session()->push('product',json_decode($request->product));
             return session('product');
            
        }
        public function listProduct(Request $request){
    //return from sessoion
            $product = $request->session()->get('product');
            return $product;
           
        }
    

    on dd() , data in network tab

    
     $products = collect($request->session()->get('product'));
          dd($products);
    
    Collection {#235
      #items: array:3 [
        0 => {#222
          +"id": 6
          +"name": "Kaylin Emard"
          +"description": "Et aperiam omnis nam iure id non fugiat. Excepturi voluptatem ipsam magnam. Esse asperiores ducimus enim et."
          +"category_id": 8
          +"price": 14
          +"image": "http://loremflickr.com/400/300?random=17"
          +"created_at": "2019-07-16 10:12:27"
          +"updated_at": "2019-07-16 10:12:27"
          +"qty": 1
        }
        1 => Collection {#223
          #items: []
        }
        2 => {#224
          +"id": 2
          +"name": "Marlene Reichert"
          +"description": "Debitis asperiores sed sit assumenda unde quo natus. Consequatur est labore tenetur quae. Eius distinctio ea omnis aspernatur porro earum quae."
          +"category_id": 3
          +"price": 76
          +"image": "http://loremflickr.com/400/300?random=71"
          +"created_at": "2019-07-16 10:12:27"
          +"updated_at": "2019-07-16 10:12:27"
          +"qty": 1
        }
      ]
    }
    

    This is the data return by second method in browser

    
    [
    {
    id: 6,
    name: "Kaylin Emard",
    description: "Et aperiam omnis nam iure id non fugiat. Excepturi voluptatem ipsam magnam. Esse asperiores ducimus enim et.",
    category_id: 8,
    price: 14,
    image: "http://loremflickr.com/400/300?random=17",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    [ ],
    {
    id: 2,
    name: "Marlene Reichert",
    description: "Debitis asperiores sed sit assumenda unde quo natus. Consequatur est labore tenetur quae. Eius distinctio ea omnis aspernatur porro earum quae.",
    category_id: 3,
    price: 76,
    image: "http://loremflickr.com/400/300?random=71",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    }
    ]
    
    Activity icon

    Replied to How To Delete Item From Session

    @snapey got this error {message: "Cannot use object of type stdClass as array",

    Aug
    05
    2 months ago
    Activity icon

    Replied to How To Delete Item From Session

    @aurawindsurfing , i got same error again

    {message: "Illegal string offset 'id'", exception: "ErrorException",…}```
    
    Activity icon

    Replied to How To Delete Item From Session

    @saurabhd ,Thanks, based on my session data above mentioned , how should it be? i tried number of above ways, didn't worked.

    Activity icon

    Replied to How To Delete Item From Session

    now its gives another error message: "Illegal string offset 'id'"

    Activity icon

    Replied to How To Delete Item From Session

    @aurawindsurfing , Thanks i got error this time on network tab

    message: "Call to a member function forget() on array"

    Activity icon

    Replied to How To Delete Item From Session

    @aurawindsurfing doing this

    $id = $request->productId;
    $products = $request->session()->get('product');
    dd($products);
    

    In my network tab i got this

    
    array:1 [
      0 => {#216
        +"id": 1
        +"name": "Keyshawn McDermott Sr."
        +"description": "Error aut quia id dolorem est aut doloribus nesciunt. Quod nihil tenetur ea id voluptas molestias id. Debitis amet dolor est fugiat sed autem."
        +"category_id": 1
        +"price": 59
        +"image": "http://loremflickr.com/400/300?random=36"
        +"created_at": "2019-07-16 10:12:27"
        +"updated_at": "2019-07-16 10:12:27"
        +"qty": 1
      }
    ]
    
    Activity icon

    Replied to Need Idea On Online Quiz

    Thanks @bobbybouwmann for giving idea. But still i have one questions. Lets say i'm tracking question based on session.

    i have two methods first method render view: quiz method second method processQuiz: i mean save user answer in db:

    In first method i need one random questions from db: lets say i do this inside quiz()method

    
         $question = Question::with('answers')
                          ->where('id', session('questions'))
                          ->inRandomOrder()
                          ->first();
    

    Before that , i need to store current question id displayed on screen in session and then only i can use above method. Obviously, i can use

    \Session::put(''questions','How to get current Question Id here') //HERE IS MY CONFUSION

    My two methods

    
    
    public function quiz(){
           
        return view('home');
    }
    
    public function processQuiz(){
        //some code to save user chosen answer in db
    }
    

    so if i use below logic

     $question = Question::with('answers')
                          ->where('id', session('questions'))
                          ->inRandomOrder()
                          ->first();
    

    i need one question ID already stored in session

    Activity icon

    Started a new conversation How To Delete Item From Session

    Hi, how can i delete data from session. it do not want delete all data by clicking single delete button. I have delete button for each data, so want to delete one by one. my current code is as follows:

    
    public function deleteProduct(Request $request){
            $id = $request->productId;// this id i want to delete which i get from view
            $products = $request->session()->get('product');
        
            foreach ($products as $key => $value)
            {
                if ($value['id'] == $id) 
                {                
                    unset($products [$key]);            
                }
            }
            //put back in session array without deleted item
            $request->session()->push('product',$products);
            //then you can redirect or whatever you need
            return redirect()->back();
    
    
        }
    

    My data in session is in below format

    
    [
    {
    id: 2,
    name: "Marlene Reichert",
    description: "Debitis asperiores sed sit assumenda unde quo natus. Consequatur est labore tenetur quae. Eius distinctio ea omnis aspernatur porro earum quae.",
    category_id: 3,
    price: 76,
    image: "http://loremflickr.com/400/300?random=71",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 6,
    name: "Kaylin Emard",
    description: "Et aperiam omnis nam iure id non fugiat. Excepturi voluptatem ipsam magnam. Esse asperiores ducimus enim et.",
    category_id: 8,
    price: 14,
    image: "http://loremflickr.com/400/300?random=17",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 5,
    name: "Prof. Iliana Mohr",
    description: "Autem sequi esse laudantium ut ut explicabo enim. Corporis cupiditate dolorum et ratione sequi architecto. Vitae enim ex hic nihil.",
    category_id: 2,
    price: 207,
    image: "http://loremflickr.com/400/300?random=99",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    }
    ]
    

    In my network tab, i got following error when i clicked the delete button

    {message: "Invalid argument supplied for foreach()", exception: "ErrorException",…}
    exception: "ErrorException"
    file: "/Applications/XAMPP/xamppfiles/htdocs/fresh/app/Http/Controllers/ProductController.php"
    line: 33
    message: "Invalid argument supplied for foreach()"
    trace: [{file: "/Applications/XAMPP/xamppfiles/htdocs/fresh/app/Http/Controllers/ProductController.php",…},…]
    0: {file: "/Applications/XAMPP/xamppfiles/htdocs/fresh/app/Http/Controllers/ProductController.php",…}
    1: {function: "deleteProduct", class: "App\Http\Controllers\ProductController", type: "->"}
    2: {,…}
    
    Activity icon

    Started a new conversation Need Idea On Online Quiz

    Hi, i am going to make online quiz. In this admin can add many questions(let say there are 100 questions) with each 4 options. This is not so hard to do

    my main challenging part is in front end. Lets say there are 100 questions in db, i want to show only 10 questions for one authenticated user, one question per page with next and previous button.

    so if i query like this

    
    $question = Question::with('answers')
                        ->inRandomOrder()->first();
    

    it still have a problem because if user do not know the answer, he may refresh page and get another question. So how do i go?? Need suggestion> Thanks

    Activity icon

    Replied to How To Get Random Question But Non Repeatable

    @willvincent Actually , i was planning to store in session do as below

    
    $question = Question::with('answers')
                       ->inRandomOrder()
                       ->whereNotIn('id',session('questions'))
                       ->first(); 
    
    $request->session()->push('questions',$request->id);
         return $request->session()->get('questions');
    

    i will use your logic provided above

    Aug
    04
    2 months ago
    Activity icon

    Started a new conversation How To Get Random Question But Non Repeatable

    Hi, i am making a simple quiz. i want to show one question at a time on screen. in my questions table , i have all quiz questions and in answers table 4 options for each question and in results table record of each questions attempt by user. so i should get one random question at a time which is not already in results table

    questions table: id,question,created_at,updated_at

    answers table:id, question_id,answer,is_correct,created_at,updated_at

    results table: id, question_id, users_id, answer ,created_at,updated_at

    i'm saving the answer submitted by user in answer column of results table.

    Now i want to show only those questions which were not attempt by that particular user. How do i query this??

    This is my attempt but unable to combine in one query.

     $question = Question::with('answers')
                        ->inRandomOrder()
                        ->first(); 
                     
    
            $qid = $question->id;
            $result = Result::where('question_id','!=',$qid)
                           ->where('user_id','!=',1)->first();
    
    
    Activity icon

    Replied to How To Delete Individual Data From Session

    Hi @snapey //this method push in session

    
    public function StoreInCart(Request $request) {
         
             $request->session()->push('product',json_decode($request->product));
             return session('product');
            
        }
    

    //this method fetch from session

    
        public function listProduct(Request $request){
            $product = $request->session()->get('product');
            return $product;
    
          
        }
    

    I want to delete with Ajax request. For now how can i delete with Laravel only

    Activity icon

    Replied to How To Delete Individual Data From Session

    @snapey i have looped the array in view(@foreach loop ), i have delete button for each data, i can get individual id in controller when i clicked the delete button. Now i want to delete based on those id. will you please give me help by providing little bit code help.

    Aug
    03
    2 months ago
    Activity icon

    Started a new conversation How To Delete Individual Data From Session

    Hi, i have data in session in below format. i want to delete the data based on id. So how my method should be in order delete data according id.

    This is data in session

    
    [
    {
    id: 5,
    name: "Prof. Iliana Mohr",
    description: "Autem sequi esse laudantium ut ut explicabo enim. Corporis cupiditate dolorum et ratione sequi architecto. Vitae enim ex hic nihil.",
    category_id: 2,
    price: 207,
    image: "http://loremflickr.com/400/300?random=99",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 2,
    name: "Marlene Reichert",
    description: "Debitis asperiores sed sit assumenda unde quo natus. Consequatur est labore tenetur quae. Eius distinctio ea omnis aspernatur porro earum quae.",
    category_id: 3,
    price: 76,
    image: "http://loremflickr.com/400/300?random=71",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 1,
    name: "Keyshawn McDermott Sr.",
    description: "Error aut quia id dolorem est aut doloribus nesciunt. Quod nihil tenetur ea id voluptas molestias id. Debitis amet dolor est fugiat sed autem.",
    category_id: 1,
    price: 59,
    image: "http://loremflickr.com/400/300?random=36",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    }
    ]
    
    

    for example when user click the delete button in view, i want to delete record with id 5.

    method:

    
    public function deleteProduct(Request $request){
            $id = $request->productId;// this gives id that is submitted from form/link
            $request->forget($id);// this delete all records
        //i want to delete only one record which user wants/clicked.
    }
    
    
    Activity icon

    Replied to Vue Js Push Is Not A Function

    @tykus works beautifully!!, Thank you so much

    Activity icon

    Replied to Vue Js Push Is Not A Function

    I made changes according to yours. But still same error, push is not a function

    
    mounted() {
                    console.log('Product mounted.')
                    var app = this;
                    axios.get('/products')
                        .then(function (resp) {
                            app.products = resp.data || [];
                        })
                        .catch(function (resp) {
                            console.log(resp);
                            alert("Could not load products");
                        });
    
                        axios.get('/list')
    
                        .then(function (resp) {
                            app.cart = resp.data
                            
                        })
    
                }
    
    Activity icon

    Replied to Vue Js Push Is Not A Function

    @tykus yes your guess is right: in mounted i have this part:

    
       axios.get('/list')
    
                        .then(function (resp) {
                            app.cart = resp.data
                            
                        })
    

    i need above part because when user refresh the page all data will be lost. so i use push to show live data in page and above to fetch same data even after page reloaded. Anyway other ways where i can show data to user as shown as added and remain same even after page reloaded

    my mounted

    
    
    mounted() {
                    console.log('Product mounted.')
                    var app = this;
                    axios.get('/products')
                        .then(function (resp) {
                            app.products = resp.data;
                        })
                        .catch(function (resp) {
                            console.log(resp);
                            alert("Could not load companies");
                        });
    
    
    //if i replace this part it works fine
                        axios.get('/list')
    
                        .then(function (resp) {
                            app.cart = resp.data
                            
                        })
    
                }
            }
    
    Activity icon

    Replied to Vue Js Push Is Not A Function

    @tykus what you mean by what else modifies cart??

    Activity icon

    Replied to Vue Js Push Is Not A Function

    @bobbybouwmann

    Still i got same error, push is not a function in dev tool i can see

    
    cart:""
     products:Array[20]
    
    Activity icon

    Replied to Vue Js Push Is Not A Function

    @tykus , in dev tool i can see

    
    cart:""
    products:Array[20]
    
    Activity icon

    Replied to Vue Js Push Is Not A Function

    i have in full code. That was part of code

    Activity icon

    Replied to Vue Js Push Is Not A Function

    i did , i got same error

    Activity icon

    Replied to Vue Js Push Is Not A Function

    @rameezisrar No, i'm not getting anything in console. when i submit button i got this error

    app.js:38298 [Vue warn]: Error in v-on handler: "TypeError: app.cart.push is not a function"
    
    found in...```
    
    Activity icon

    Started a new conversation Vue Js Push Is Not A Function

    Hi, i am making a small app with laravel and vuejs. I'm getting an error, the push is not a function when I clicked an add to cart button. Everything is working here fine but methods addProductToCart gives error push is not a function. when I first click add product to cart button it gives that error and once I refresh the page I can see a product in cart and again if click adds to cart button this time error is not seen, works perfectly. when cart[] is empty it gives error push is not a function, but when cart[] has at least one element I don't get that error. Any help would be greatly appreciated.

    
    <div v-for="product in products" >
              <div class="card" >
                <div class="card-header">{{product. name}}</div>
    
                <div class="col-md-4">
    
                    <div class="card-body">
                            <img :src="product.image">
                            <p>{{product.price}}</p>
                            <p>{{product.category_id}}</p>
                        </div>
                    <button class="btn btn-primary"  @click="addProductToCart(product)">
                     
                    </button>
                    </div>
    
                </div>
            
         
            
            </div>
    
    
    <script>
        export default {
    
            data:function(){
                return {
                    products:[],
                    
                    cart:[]
    
                }
    
            },
            methods:{
    
    
                addProductToCart(product){
                    var app = this;
                          
                        app.cart.push(product)
    
    
                    axios.get('/cart',{
    
                         params: {
                            product: product,
                        }
    
                    }).then((response)=>{
    
                    });
    
                
                }
    ,
     mounted() {
                    console.log('Product mounted.')
                    var app = this;
                    axios.get('/products')
                        .then(function (resp) {
                            app.products = resp.data;
                        })
                        .catch(function (resp) {
                            console.log(resp);
                            alert("Could not load companies");
                        });
    
                       
    //if i replace this part it works fine
                        axios.get('/list')
    
                        .then(function (resp) {
                            app.cart = resp.data
                            
                        })
    
                }
            
                }
    </script>
    

    my /products return data in below format

    
    [
    {
    id: 1,
    name: "Keyshawn McDermott Sr.",
    description: "Error aut quia id dolorem est aut doloribus nesciunt. Quod nihil tenetur ea id voluptas molestias id. Debitis amet dolor est fugiat sed autem.",
    category_id: 1,
    price: 59,
    image: "http://loremflickr.com/400/300?random=36",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 2,
    name: "Marlene Reichert",
    description: "Debitis asperiores sed sit assumenda unde quo natus. Consequatur est labore tenetur quae. Eius distinctio ea omnis aspernatur porro earum quae.",
    category_id: 3,
    price: 76,
    image: "http://loremflickr.com/400/300?random=71",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    
    {
    id: 19,
    name: "Syble Turner PhD",
    description: "Consequatur aut et eos sunt blanditiis vel. Tempore ut labore enim eos. Quia cupiditate vel nihil eius repellendus.",
    category_id: 9,
    price: 231,
    image: "http://loremflickr.com/400/300?random=18",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    },
    {
    id: 20,
    name: "Dayana Macejkovic",
    description: "Sit quo qui et consequuntur culpa. Quia occaecati sunt sequi recusandae est. Ea autem doloremque odio dolores ut.",
    category_id: 1,
    price: 285,
    image: "http://loremflickr.com/400/300?random=1",
    created_at: "2019-07-16 10:12:27",
    updated_at: "2019-07-16 10:12:27",
    qty: 1
    }
    
    Aug
    01
    2 months ago
    Activity icon

    Started a new conversation Online Exam Quiz App Help Needed

    Hi, i am making a quiz application with Laravel. I am stuck here.

    my main question/problem

    1. How to randomly fetch one question with four answer per page . I have 50 questions with answer in table
    2. Among 50 question i want to allow user to attempt any 10 no-repeatable questions
    3. Each question should have previous and next button. on 10th question it should show submit button
    4. Only logged in users attempt the question.

    will you please give me some idea about solving these 4 problem. I have main difficulty in question no.1 , fetching one question at a time and showing next button

    users table

    //....

    quizees table

        public function up()
        {
            Schema::create('quizzes', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('name');
                $table->timestamps();
            });
        }
    

    Answers table

    
    
    
    public function up()
        {
            Schema::create('questions', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('quiz_id')->unsigned()->index();
                $table->string('body');
                $table->timestamps();
            });
        }
    

    questions table

    
    
    
        public function up()
        {
            Schema::create('questions', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('quiz_id')->unsigned()->index();
                $table->string('body');
                $table->timestamps();
            });
        }
    

    Answer.php

    
    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    use App\Question;
    class Answer extends Model
    {
        public function question() {
            return $this->belongsTo(Question::class);
        }
    }
    

    Question.php

    
    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    use App\Quiz;
    use App\Answer;
    
    class Question extends Model
    {
        public function quiz() {
            return $this->belongsTo(Quiz::class);
        }
    
        public function answers() {
            return $this->hasMany(Answer::class);
        }
    }
    

    method

    
        public function quiz()
        {
            $question = Question::with('answers')->get();
            return $question;
            return view('home',compact('question'));
        }
    

    output around 50 questions

    
    [
    {
    id: 1,
    quiz_id: 1,
    body: "what is 2+2?",
    created_at: null,
    updated_at: null,
    answers: [
    {
    id: 1,
    question_id: 1,
    answer: "4",
    is_correct: 1,
    created_at: null,
    updated_at: null
    },
    {
    id: 2,
    question_id: 1,
    answer: "2",
    is_correct: 0,
    created_at: null,
    updated_at: null
    },
    {
    id: 3,
    question_id: 1,
    answer: "3",
    is_correct: 0,
    created_at: null,
    updated_at: null
    },
    {
    id: 4,
    question_id: 1,
    answer: "1",
    is_correct: 0,
    created_at: null,
    updated_at: null
    }
    ]
    },
    {
    id: 2,
    quiz_id: 1,
    body: "what is square of 3",
    created_at: null,
    updated_at: null,
    answers: [
    {
    id: 9,
    question_id: 2,
    answer: "3",
    is_correct: 0,
    created_at: null,
    updated_at: null
    },
    {
    id: 10,
    question_id: 2,
    answer: "9",
    is_correct: 0,
    created_at: null,
    updated_at: null
    },
    {
    id: 11,
    question_id: 2,
    answer: "4",
    is_correct: 0,
    created_at: null,
    updated_at: null
    },
    {
    id: 12,
    question_id: 2,
    answer: "6",
    is_correct: 0,
    created_at: null,
    updated_at: null
    }
    ]
    },
    {
    id: 3,
    quiz_id: 1,
    body: "what is colour of blood",
    created_at: null,
    updated_at: null,
    answers: [
    {
    id: 5,
    question_id: 3,
    answer: "yellow",
    is_correct: 0,
    created_at: null,
    updated_at: null
    },
    {
    id: 6,
    question_id: 3,
    answer: "red",
    is_correct: 0,
    created_at: null,
    updated_at: null
    },
    {
    id: 7,
    question_id: 3,
    answer: "blue",
    is_correct: 0,
    created_at: null,
    updated_at: null
    },
    {
    id: 8,
    question_id: 3,
    answer: "pink",
    is_correct: 0,
    created_at: null,
    updated_at: null
    }
    ]
    }
    ]
    

    Any help would be greatly appreciated

    Jul
    31
    2 months ago
    Activity icon

    Replied to Push Is Not A Function Vuejs

    Any help would be highly appreciated?

    Jul
    30
    2 months ago
    Activity icon

    Started a new conversation Quiz App Laravel

    Does anyone has a QUIZ app made with Laravel or Laravel+vue js, can you share your project source code . I t would be a great help . please share the link of project or tutorial if you have.. Thanks

    Jul
    27
    2 months ago
    Activity icon

    Replied to Session Data Not Displayed In Vue For Loop

    using json_decode() This solved $request->session()->push('product',json_decode($request->product));