【发布时间】:2021-07-16 13:25:57
【问题描述】:
我需要将这些参数 data_from 和 data_to 传递给 axios 调用,但它不起作用。我做错了什么?响应未定义。
控制器:
class PaymentController extends Controller
{
public function apiPaymentByUserId(Request $request) {
$data_from = $request -> data_from;
$data_to = $request -> data_to;
$payments = DB::table("casefiles, payments")
->select("payments.*")
->where("casefiles.id", "=", 'payments.casefile_id')
->where("casefiles.user_id", "=", Auth::id())
->where("payments.created_at", ">=", $data_from)
->where("payments.updated_at", "<=", $data_to)
->get();
return response()->json([
'success' => true,
'response' => $payments
]);
}
}
路线:
Route::post('/payments', 'Api\PaymentController@apiPaymentByUserId');
用vue js调用axios:
axios.post('/payments', {
params: {
data_from: this.data_from,
data_to: this.data_to
}
})
【问题讨论】: