令人困惑的情况LARAVEL

时间:2017-11-10 17:25:34

标签: php laravel laravel-5

我处于非常混乱的状态

我有像这样的控制器逻辑

public function book(Request $request)
{
  //setting API class
  $business = new API();

  //getting name and number for sending verification code
  $name = $request->name;
  $number = $request->number;

  //sending verification code to number 
  $business->sendVerificationCode($number);

 //sending user back to show a form to enter verification code
 return back()->with('modalForEnteringConfirmation', ' ');

}

我将验证码发送到请求的号码。 我将返回一个模式,其中包含一个输入验证码的表单。

我的问题是获取该verifyCode值,以便我可以在我的book控制器中继续进行

//receiving confirmation code
$code = $request->confirmation;

//booking if confirmation code matches
$book = $business->bookingNumber($name, $code);

现在,我无法在back()函数中发送变量,我该如何获取确认码?我似乎无法得到它。

1 个答案:

答案 0 :(得分:2)

您可以使用with功能上的back将闪回数据发送到下一个请求。因此,在您的视图中,您必须使用request()->session()->get()session()辅助方法检查该数据:

假设您通过控制器发送验证码,如下所示:

...
return back()->with('verification_code', $verification_code);

然后在您的视图中,您将在模式中包含verification_code

<-- Say this is your modal content section -->
@if (request()->session()->has('verification_code'))
      {{ request()->session()->get('verification_code') }}
    // you should have the code here
@endif

当然我不知道你是如何构建你的模态表单的,但是在编写html代码时,如果你在表单中包含了如上所述的那些数据,那么你应该在它找到它时随时使用它。