I have an object which also contain an array of multiple objects like this:
let obj = {
owner: 'Smith',
cats: [
{
color: 'black',
name: 'kitty',
},
{
color: 'orange',
name: 'kian'
}
]
}
How can I pass this data in the controller create function? I'm using AXIOS to send a post request
axios.post(this.url + 'cat_lovers/create', obj)
.then(function (res) {
//some codes
})
to store the data on the database
public function create() {
$data = [
'owner' => $this->input->post('owner'),
'cats' => serialize($this->input->post('cats')),
];
if ($this->cat_model->create($data)) {
$res['error'] = false;
$res['msg'] = CREATE_SUCCESS;
}
echo json_encode($res);
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment