lundi 24 septembre 2018

laravel api with react native post request

I'm using laravel api as a backend and react native as a frontend i trying to post some data to my api but some times added successfully and some times it give me ( Request failed with status code 500 )

this is my api code

public function addNumber(Request $request)
{
    $new = new ServiceRequest;
    $new->office_id = $request->office_id;
    $new->national_number = $request->national_number;
    $new->date = $request->date;
    $new->time = $request->time;
    $new->save();


    $detail = new ServiceRDetail ;
    $detail->request_id = $new->id;
    $detail->service_id  = $request->service_id;
    $detail->national_number = $request->national_number;   

    $detail->save();

    return response()->json(['success'=>'Added'],$this->successStatus); 

}

and this is my react native code

manage = () => {


const national_number=this.state.pid;
const office_id=this.state.office_id;
const service_id=this.state.service_id;
const date=this.state.date;
const time=this.state.time;
 const  url='http://MyIP/api/add_number';
axios.post(url,{national_number,office_id,service_id,date,time})
.then(resp => alert('added')).catch(err => alert(err));


}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire