0

I need to foreach array from session. My controller code

return [
        'buys' => request()->session()->get('userBuys')
      ];

Vue component

export default {
    data() {
      return {
        buys: {}
      }
    },
    methods: {
        async getBuys() {
            this.$axios.post('/products/mybuys')
                .then(res => {

                    this.buys = res.data.buys
                    
                    this.$root.hideLoading()
                })
        }
    },
    mounted() {
        this.$root.showLoading()
        this.getBuys()
    }
}

So i'm getting array Text How i need to foreach this array correctly? I tried a lot of...

1

1 Answer 1

0

You have a json in a array so your

buys = [113, 114,...]

So your loop have only the numbers not the propertys/attributes

Try without brackets:

return 'buys' => request()->session()->get('userBuys')
Sign up to request clarification or add additional context in comments.

9 Comments

@AlexeyKotoff so "buys" is empty, please show more code
let me see your whole axios call and where you initialize buys
check vue component topic
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.