【发布时间】:2015-03-20 05:48:36
【问题描述】:
我设计了一个带有输入验证的联系页面,如果验证成功通过,则会发送电子邮件。我在发送电子邮件后遇到问题,$sent 变量没有传递到刀片视图以确认用户?
在contact.blade.php文件中,
@if (isset($sent) && $sent == true)
<p>Your details have been successfully send to us we will contact you shortly.</p>
@endif
在控制器中,显示一个/contact 页面(GET)
public function showContact()
{
$data = [];
return View::make('contact')->withData($data);
}
在控制器中,当用户按下提交按钮 (POST)
public function postContact()
{
$contactRules = [
'contact_name' => 'required',
'contact_email' => 'required|email',
];
$validator = Validator::make(Input::all(), $contactRules);
if ($validator->fails()) {
return Redirect::to('/contact')->withErrors($validator)->withInput();
}
$emailData['contact_name'] = Input::input('contact_name');
$emailData['contact_email'] = Input::input('contact_email');
Mail::send('emails.contact', $emailData, function ($message) {
$message->to('email@domain.net', 'Name Name')->subject('Subject Here');
});
// Problem Here - $sent varible not passing through to view to confirm user?
return Redirect::to('/contact')->with('sent', true);
}
发送电子邮件后,它会重定向回/contact 页面但with('sent', true); 没有通过?
【问题讨论】: