laravel 4重定向问题

时间:2013-12-08 09:24:40

标签: laravel laravel-4 laravel-routing

我有一份注册表,它一直在工作,直到它没有。我确信我对代码做了一些事情,因为我是laravel 4的新手,所以我无法确定我做错了什么。现在我正在

  

此网页有一个重定向循环。

这是路线档案:

Route::get('/','MainController@index');

Route::get('/login', 'MembersController@login');

Route::get('/signup', 'MembersController@signup');

/*handled by controller to register the user that signed up*/
Route::get('/register', 'MembersController@register');

/* Handle authenticating a user when loggin in*/


Route::post('register', array(
  'uses' => 'MembersController@register',
  'as' => 'members.register'
));

这是表格开头:

@section('content')
{{ Form::open(array('route' => 'members.register')) }}    

......

{{ Form::close() }}
@stop

这是验证,如果出现错误,它会再次重定向到注册页面并显示它们(直到它崩溃为止)

public function register()
    {
        $rules = array(
            # place-holder for validation rules
            'firstname' => 'Required|Min:3|Max:40|Alpha',
            'lastname' => 'Required|Min:3|Max:40|Alpha',
            'email'     => 'Required|Between:3,64|Email|Unique:users',
            'country'       => 'Required',
            'password'  =>'Required|AlphaNum|Between:7,15|Confirmed',
            'password_confirmation'=>'Required|AlphaNum|Between:7,15'

        );

        /*Create new user if no user with entered email exists. Use validator to ensure all fields are completed*/
        $user = new User;

        $validator = $this->validate(Input::all(), $rules);
        if ($validator->fails())
        {

            return Redirect::to('register')->withErrors($validator);

        }else{
            echo "Success";
        }

    }

感谢您的帮助:)

1 个答案:

答案 0 :(得分:3)

更改以下行

return Redirect::to('register')->withErrors($validator);

使用此

return Redirect::back()->withInput()->withErrors($validator);

您无限次地呼叫路由寄存器。

也删除此路线。你只需要邮寄路线。

/*handled by controller to register the user that signed up*/
Route::get('/register', 'MembersController@register');