douwanc63652 2016-11-01 09:31
浏览 65

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

I have a POST route in Laravel:

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

On the view for this route I have a form that submits to another route:

Route::post('/proceed-to-payment', 'QuoteController@proceedToPayment')->name('proceed-to-payment');

Here is my controller method for 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() method:

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');

    }

I am trying to redirect back to quote-summary but as it was a POST I am getting a MethodNotAllowedHttpException as the redirect seems to be doing a GET.

Any ideas on how I can return to my POST route with some validation error messages?

  • 写回答

1条回答 默认 最新

  • duandi1636 2017-09-29 06:20
    关注

    Having both, post and get, routes for your quoteSummary action, would do just what you are after, i.e.:

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

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题