我在Laravel有一条POST路线:
Route::post('/quote-summary', 'QuoteController@quoteSummary')->name('quote-summary');
在此路线的视图中,我有一个提交到另一条路线的表格:
Route::post('/proceed-to-payment', 'QuoteController@proceedToPayment')->name('proceed-to-payment');
以下是proceed-to-payment
的控制器方法:
public function proceedToPayment(Request $request) {
if(empty($request->get('tick_statement_of_fact'))) {
return redirect()->route('quote-summary')->with('tick_statement_of_fact', 'I am so frustrated.');
} else {
return view('quote.payment', compact('date_cover_required', 'expiry_date'));
}
}
quoteSummary()方法:
public function quoteSummary(QuoteRequest $request)
{
//dd($request);
// get the quote
$quote_data = $this->getQuote($request);
$quote = number_format($quote_data, 2, '.', ',');
if(!empty($request->get('units'))) {
$units = $request->get('units');
}
if(!empty($request->get('limit_of_indemnity'))) {
$limit_of_indemnity = number_format($request->get('limit_of_indemnity'), 2, '.', ',');
}
if(!empty($request->get('title'))) {
$title = $request->get('title');
}
// store data in the session so we can access from generated documents
session(['units' => $units, 'limit_of_indemnity' => $limit_of_indemnity, 'insured_name' => $insured_name, 'title' => $title, 'first_name' => $first_name, 'last_name' => $last_name, 'contact_number' => $contact_number, 'email' => $email, 'quote' => $quote]);
return view('quote.summary');
}
我正在尝试重定向回quote-summary
但因为它是POST
我得到MethodNotAllowedHttpException
,因为重定向似乎正在执行GET
。
关于如何使用一些验证错误消息返回POST路径的任何想法?
答案 0 :(得分:1)
同时拥有,发布和获取您的quoteSummary操作的路由,将完成您所追求的目标,即:
Route :: post('/ quote-summary','QuoteController @ quoteSummary') - > name('quote-summary'); Route :: get('/ quote-summary','QuoteController @ quoteSummary') - > name('quote-summary');