带有响应本机发布请求的laravel API

时间:2018-09-24 09:59:40

标签: api react-native laravel-5 axios

我将laravel api用作后端,将react本机用作前端。

我试图将一些数据发布到我的api中,有时有时会成功添加,有时会给我一个错误

  

请求失败,状态码为500

这是我的api代码:

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); 

}

这是我的react本机代码:

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));


}

0 个答案:

没有答案