Add v-model to it?
Dec 5, 2015
25
Level 51
Get a certain ID on a edit page
I have a standard edit page like so:
{!! Form::model($product, ['method' => 'PATCH', 'url' => ['admin/products', $product->id], 'class' => 'form-horizontal', 'files' => true]) !!}
<input type="hidden" name="product_id" value="{!! $product->id !!}">
<div class="form-group">
<label class="col-sm-2">Category</label>
<div class="col-sm-10">
{!! Form::select('category_id', $categories, $product->category_id, ['class' => 'form-control']) !!}
</div>
</div>
blah blah blah
{!! Form::close() !!}
I want to grab the ID then pass that to my Vue instance to then grab all the options for that product.
// Vue
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('value');
Vue.config.debug = true;
new Vue({
el: '#productOptions',
data: {
options: [
]
},
ready: function() {
this.fetchOptions();
},
methods: {
// Fetch all options for given product
fetchOptions: function() {
this.$http.get('/admin/getProductOptions', function(options) {
this.$set('options', options);
console.log(options);
});
},
// This onUpdate method I need the product ID to be able to update the right record.
onUpdate: function(e) {
e.preventDefault();
this.options.push(options);
this.$http.post('/admin/updateProductOption', options);
window.history.go(-1);
},
},
});
Please or to participate in this conversation.