简体   繁体   English

如何使用$ request-> all()将表单值从一个视图转发到另一个视图; ? Laravel 5

[英]How to forward form values from one view to another using $request->all(); ? Laravel 5

I pull all the values (topup amount and phone number) from a form on the index page and forward it to the checkout page: 我从索引页面上的表单中提取所有值(充值金额和电话号码)并将其转发到结帐页面:

public function topupPost(Request $request) {
        $validator = [
        'topupAmount'=> 'required|integer|between:1,100',
        'phonenumber'=> 'required|regex:/^05[602][0-9]{7}$/',
        ];

        $inputs = $request->all();

        Log::info($inputs);

        $validator = Validator::make($inputs, $validator);

        if($validator->fails()){
            return Response::json([
                'error' => true,
                'message' => $validator->messages(),
                'code' => 400
            ], 400);
        }


        // return "Thanks! we'll take you to payment in a Giffy!";
        return view('pages.checkout', compact(inputs));
    }

How can I can I access the values of inputs which are: phonenumber and topupAmount in the checkout page template ? 我如何访问结帐页面模板中的inputs值: phonenumbertopupAmount

I tried this: 我尝试了这个:

<td>{{ app('inputs')->input('topupAmount') }} USD</td>

And it shows this error in the debugger : 它在调试器中显示此错误:

(1/1) ErrorException Use of undefined constant inputs - assumed 'inputs' in PagesController.php (line 39) at HandleExceptions->handleError(8, 'Use of undefined constant inputs - assumed \\'inputs\\'', 'C:\\xampp\\htdocs\\onlinerecharge\\app\\Http\\Controllers\\PagesController.php', 39, array('request' => object(Request), 'validator' => object(Validator), 'inputs' => array('_token' => 'CsySUUecI0ekYNPY6oS1B2kleVHqNnrUKBpHbYwa', 'phonenumber' => '0501234567', 'topupAmount' => '1'))) in PagesController.php (line 39) (1/1)ErrorException使用不确定的常量输入-在HandleExceptions-> handleError(8,'使用不确定的常量输入-假设\\'inputs \\','C:在PagesController.php(第39行)中假定为'inputs': \\ xampp \\ htdocs \\ onlinerecharge \\ app \\ Http \\ Controllers \\ PagesController.php',39,array('request'=> object(Request),'validator'=> object(Validator),'inputs'=> array(' _token'=>'CsySUUecI0ekYNPY6oS1B2kleVHqNnrUKBpHbYwa','phonenumber'=>'0501234567','topupAmount'=>'1'))))在PagesController.php(第39行)

您可以按以下方式访问pages / checkout.blade.php中的值:

{{ $inputs['phonenumber'] }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM