Session Laravel4不显示旧::输入()
laravel4新手,无法实现基本功能,例如:Session Laravel4不显示旧::输入(),session,laravel-4,Session,Laravel 4,laravel4新手,无法实现基本功能,例如: function doRegister() { try { $email = Input::get('email'); $type = Input::get('type'); // <-- Data from radio button # Check if email exists if ( User::where('email','=',$email)->c
function doRegister() {
try {
$email = Input::get('email');
$type = Input::get('type'); // <-- Data from radio button
# Check if email exists
if ( User::where('email','=',$email)->count() > 0 ) {
# This account already exists
throw new Exception( 'This email already in use by someone else.' );
}
} catch (Exception $e) {
return Redirect::to('/')->withInput()->with('message', $e->getMessage() );
}
}
函数doRegister(){
试一试{
$email=Input::get('email');
$type=Input::get('type');//count()>0){
#此帐户已存在
抛出新异常('此电子邮件已被其他人使用');
}
}捕获(例外$e){
返回Redirect::to('/')->withInput()->with('message',$e->getMessage());
}
}
现在在主页
控制器(即/
)上,我无法读取输入::old('type')的值代码>
它返回空的。为什么呢?试试这个:
function doRegister()
{
$rules = array('email' => 'required|email|unique:users');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('/')->withInput()>withErrors($validator);
}
else {
$email = Input::get('email');
$type = Input::get('type');
// Register...
}
}
您可以使用以下方法检索验证错误:
$errors->first('email');
在您的视图中如何使用Input::old(…)
?重定向后是否会收到消息
?我确实收到消息
,但在控制器上,当我回显输入::old('type')
其空时,如果它不在会话中,是否可以使用输入::flash()代码>在重定向到主页然后尝试获取旧输入之前?另外,您可以在主页上使用dd(session::all())
检查会话数据。哦,等等,我之前有另一个重定向,没有->withInput()…所以它没有通过!我现在明白了。谢谢很高兴你得到它,并尝试我的答案,这是更好的和正确的方式来验证独特的电子邮件。