Vue.Js Programming Tutorials, Guides & Best Practices
Explore 2+ expertly crafted vue.js tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.
Adblocker Detected
It looks like you're using an adblocker. Our website relies on ads to keep running. Please consider disabling your adblocker to support us and access the content.
Building a Custom E-commerce Platform with Laravel and Vue.js
 Tutorial  August 27, 2024 
 javascript  php 
Create a Checkout.vue component in resources/js/components/Checkout.vue:
<template>
  <div>
    <h1>Checkout</h1>
    <div v-for="item in cart" :key="item.id">
      <h2>{{ item.name }}</h2>
      <p>Quantity: {{ item.quantity }}</p>
      <p>Total Price: {{ item.quantity * item.price }}</p>
    </div>
    <h3>Total: {{ cartTotal }}</h3>
    <button @click="placeOrder">Place Order</button>
  </div>
</template>
<script>
export default {
  computed: {
    cart() {
      return this.$store.getters.cartItems;
    },
    cartTotal() {
      return this.$store.getters.cartTotal;
    },
  },
  methods: {
    placeOrder() {
      axios.post('/api/orders', {
        user_id: this.$store.state.user.id, // Assuming user info is stored in Vuex
        items: this.cart,
        total_price: this.cartTotal,
      }).then(() => {
        this.$router.push('/orders');
      });
    },
  },
};
</script>