vendredi 2 août 2019

Post array from ReactNative by Axios to Laravel Controller and use ForEach loop

I am trying to post the whole state by using axios which contains single values and an array. However I can access the single values but getting error to get the array which i want to loop through. My codes are :

sendData() {    
    let api = 'myapi'
    var data = this.state

    axios.post(api, data).then((response) => {
        console.log('respp: ',response)
    })
    .catch((error) => {
            console.log(error)
    })
}

Controller:

public function getData(Request $request) {
        $user_id = $request->user_id;
        $items = $request->items;
        foreach($items as $key => $item) {
            echo $item;
        }
    }

I want to get the array and loop through it. Any help?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire