我对Laravel服务器进行了Retrofit API调用:
@POST("/dualsimlog")
Call<ResponseBody> submitLogs(@Body List<ServerLog> serverLogs);
以下是Retrofit实施:
List<ServerLog> unsubmitted = logHelper.getLogInfo();
retrofit2.Call<ResponseBody> call = logServices.submitLogs(unsubmitted);
call.enqueue(new retrofit2.Callback<ResponseBody>() {
@Override
public void onResponse(retrofit2.Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
L.m(response.message());
}
@Override
public void onFailure(retrofit2.Call<ResponseBody> call, Throwable t) {
L.m("Submission failed.");
}
});
单个对象的My Laravel商店API是:
public function store(Request $request)
{
// validating object variables
$rules = [
'device_id' => 'required|string',
'type' => 'required|string',
'sim1_cost' => 'required|numeric|min:0',
'sim2_cost' => 'required|numeric|min:0',
'cost_saved' => 'required|numeric|min:0',
'call_duration' => 'required|numeric|min:0',
'created_at' => 'required|date',
];
$data = $request->all();
$validator = Validator::make($data, $rules);
if ($validator->fails()) {
return $this->errorResponse("Validation error.",400 );
}
$product = DualSimLog::create($data);
return $this->showMessage("Successful.");
}
如何修改API以验证和插入ServerLog
对象列表?
此外,在使用Android发送API请求时,如何在PhpStorm中调试Laravel项目?