Php 函数App\Http\Controllers\RaveController::addToOrdersTables()的参数太少,已传递0个,预期正好是2个
嗨,我使用RaveWave作为我的支付网关。我想在客户完成付款时存储订单,但我无法通过该错误。我不知道我错过了什么。 谢谢你的帮助,这是我的代码Php 函数App\Http\Controllers\RaveController::addToOrdersTables()的参数太少,已传递0个,预期正好是2个,php,laravel,laravel-7,Php,Laravel,Laravel 7,嗨,我使用RaveWave作为我的支付网关。我想在客户完成付款时存储订单,但我无法通过该错误。我不知道我错过了什么。 谢谢你的帮助,这是我的代码 public function callback(Request $request) { // $data = Rave::verifyTransaction(request()->txref); $resp = $request->resp; $body = json_decode($resp, true
public function callback(Request $request)
{
// $data = Rave::verifyTransaction(request()->txref);
$resp = $request->resp;
$body = json_decode($resp, true);
$txRef = $body['data']['data']['txRef'];
$data = Rave::verifyTransaction($txRef);
return redirect()->route('success');
}
这是我的路线
Route::get('/success', 'RaveController@addToOrdersTables')->name('success');
这是我保存订单的方法
protected function addToOrdersTables($request, $error)
{
$order = Order::create([
'user_id' => auth()->user() ? auth()->user()->id : null,
'billing_email' => $request->email,
'billing_first_name' => $request->first_name,
'billing_last_name' => $request->last_name,
'billing_address' => $request->address,
'billing_city' => $request->city,
'billing_town' => $request->town,
'billing_postalcode' => $request->postalcode,
'billing_phone' => $request->phone,
'billing_total' => Cart::getTotal(),
'error' => $error,
]);
foreach (Cart::getContent() as $item)
{
OrderProduct::create([
'order_id' => $order->id,
'product_id' => $item->model->id,
'quantity' => $item->quantity,
]);
}
}
谢谢关心。您还必须通过路由传递参数:
Route::get('/success/{error}', 'RaveController@addToOrdersTables')->name('success');
在addToOrdersTables
方法类型中,使用request
提示请求,如下所示:
protected function addToOrdersTables(Request $request, $error)
请不要垃圾邮件标签,您使用的是5或7?Am使用的是laravel-7-XY。您需要在通话中键入提示请求,并使用
request$request
。我不知道$error
是什么,但您需要传入它,从函数调用中取出它并从$request
获取它,或者找出它应该来自哪里。我还建议重命名路由<代码>成功和$error
在我看来是矛盾的。它可以是result/{$status?}
方法定义为(Request$Request$status)
他也可以使用{error?}将其作为可选参数-我假设不会总是有错误