I have a form used to post product in a shopping cart, I have a Vuejs component setup and it retrieves data just fine, but when I try adding a select tag, I can't pass the data from it. Here's my code for the blade.php file:
<form action="{{ url('/cart') }}" method="POST" class="side-by-side">
<input type="hidden" name="id" v-model="this.id" value="{{ $product->id }}">
<input type="hidden" name="name" v-model="this.name" value="{{ $product->name }}">
<input type="hidden" name="price" v-model="this.price" value="{{ $product->price }}">
{{-- Can't figure out how to pass the following --}}
<select v-model="selected" required>
<option disabled value="">Please select one</option>
@foreach($product->withOptions() as $option)
<option value="{{ $option->options }}">{{ $option->options }}</option>
@endforeach
</select>
<addToCart :product="{{ $product }}"></addToCart>
and here's my vue file:
export default {
props: ['product'],
data() {
return {
id: this.product.id,
quantity: 1,
name: this.product.name,
price: this.product.price,
selected: '' // always null, can't figure it out
}
},
methods: {
addtocart() {
axios.post('/cart/', this.$data)
.then(flash(this.product.name + ' was added to cart'));
}
}
}
Thank you for your help.