Laravel 5如何返回带有验证错误的POST请求

时间:2016-11-01 09:31:44

标签: php laravel laravel-5 request

我在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路径的任何想法?

1 个答案:

答案 0 :(得分:1)

同时拥有,发布和获取您的quoteSummary操作的路由,将完成您所追求的目标,即:

Route :: post('/ quote-summary','QuoteController @ quoteSummary') - > name('quote-summary'); Route :: get('/ quote-summary','QuoteController @ quoteSummary') - > name('quote-summary');