I have a fairly simple axios call going on within a vue component where I'm taking an array from the data and sending it via post URL to a php class that's trying to work with it. The current issue is that when it hits the php function, I'm getting an array to string conversion error, though I feel like the structure is correct within the data object in vue.
Tne php function is:
public function testStores( array $stores = null){
$storeTest = empty($stores) ? '' : "STORES:".implode(',',$stores). ";
}
Implode isn't working here due to the array to string issue, but I would expect $storeTest
to give me "5, 10" in this case. Just a comma separated string made from the IDs.
What have I done wrong?
UPDATE: I'm dumping the array now, right before I call the implode function, and this is what prints:
array:2 [
0 => array:1 [
"id" => "5"
]
1 => array:1 [
"id" => "10"
]
]
var vm =
new Vue({
el: "#app",
data: {
stores: [
{id: "5"},
{id: "10"}
]
},
methods: {
getStores(){
axios({
method: 'post',
url: test,
data: {
stores: this.stores
}
}).then(function (response) {
}).catch(function (error) {
});
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<button @click="getNames()">TEST</button>
</div>