如何使用 $request->all(); 将表单值从一个视图转发到另一个视图? Laravel 5
How to forward form values from one view to another using $request->all(); ? Laravel 5
我从索引页面的表格中提取所有值(充值金额和 phone 号码)并将其转发到结帐页面:
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));
}
如何在结帐页面模板中访问 inputs
的值:phonenumber
和 topupAmount
?
我试过这个:
<td>{{ app('inputs')->input('topupAmount') }} USD</td>
它在调试器中显示了这个错误:
(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)
您按如下方式访问 pages/checkout.blade.php 中的值:
{{ $inputs['phonenumber'] }}
我从索引页面的表格中提取所有值(充值金额和 phone 号码)并将其转发到结帐页面:
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));
}
如何在结帐页面模板中访问 inputs
的值:phonenumber
和 topupAmount
?
我试过这个:
<td>{{ app('inputs')->input('topupAmount') }} USD</td>
它在调试器中显示了这个错误:
(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)
您按如下方式访问 pages/checkout.blade.php 中的值:
{{ $inputs['phonenumber'] }}