Reputation: 9247
I have an array of values in vue.js, but problem is that I need to pass that values to controller. How can I do that, or is that a wrong way?
This is in my vue.js where I get values:
additional_features: this.additionals_features
this.$http.patch('/profile/'+ user_id +'/property/'+ property_id +'/edit', property_credentials).then(function(response) {
$("html, body").animate({ scrollTop: 0 }, "slow");
this.property_status = true;
this.property_success_update_message = response.data.successUpdateMsg;
} , function(response) {
$("html, body").animate({ scrollTop: 0 }, "slow");
this.property_status = false;
this.property_errors = response.data
});
This is my controller
$additional_features = $request->input('additionals_features');
This is my html:
<input type="hidden" v-model="property_credentials.additional_features" name="additional_feature[]" value="@{{property_credentials.additional_features}}" />
Upvotes: 0
Views: 5974
Reputation: 87719
You can use vue-resource and send it using post:
new Vue({
el: '#app',
data: {
token: '{{ csrf_token() }}',
property_credentials: {
additionals_features: [],
}
},
methods: {
submit: function() {
this.$http.post('/your-api-url', {
'_method': 'patch',
'_token': this.token, // You must pass this token on post requests
'additionals_features': this.property_credentials.additionals_features,
});
}
}
});
The data will arrive directly in your controller, so you can probably
$additional_features = $request->get('additionals_features');
What you do with this data once it arrives in the controller, it's up to you.
Upvotes: 4