My project allows the clients to put items into their cart. where each item relate to a shop with the shop_id
. I would want to list out the items in the cart view. However, I want these items to be grouped under a table for those that have the same shop_id
. So if the client bought from 3 different shops, there will be 3 tables in the cart view where each table consists of the respective items that the client bought from that shop. Is there a good way to do this?
Here is my unfinished Cart.vue code for your reference but I dont think it can help much
<template>
<div class="row">
<div class="col-md-12 cart-container">
<table class="table table-hover" v-for="cart in carts">
<thead>
<tr>
<th>{{cart.shop.name}}</th> //cart includes shop by eloquent
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="cart-img-wrapper">
<img class="cart-img" :src="cart.product_choice.img1">
</div>
</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<script>
export default {
data(){
return{
carts:{},
}
},
props:[
],
mounted(){
this.getCartItems()
},
updated(){
},
methods:{
getCartItems(){
var vm = this
vm.$http.get('/getCartItems/').then((response)=>{
vm.carts = response.data
});
},
},
computed:{
}
}
</script>
my carts table structure:
Schema::create('carts', function (Blueprint $table) {
$table->increments('id');
$table->integer('product_id')->unsigned();
$table->integer('product_choice_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->integer('shop_id')->unsigned();
$table->integer('qty');
$table->integer('complete')->default(0);
$table->timestamps();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('product_id')
->references('id')
->on('products')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('shop_id')
->references('id')
->on('shops')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('product_choice_id')
->references('id')
->on('product_choice')
->onDelete('cascade')
->onUpdate('cascade');
});