manavo / laravel-bootstrap-forms

ABANDONED - Using @stidges' code for bootstrap forms to create a composer package.
http://blog.stidges.com/post/easy-bootstrap-forms-in-laravel
MIT License
19 stars 12 forks source link

Errors not working #2

Closed ghost closed 10 years ago

ghost commented 10 years ago

I am not able to see any validation errors.

Here is my controller :

   public function getCreate()
    {
            return View::make('user.login');
    }

    public function postCreate()
    {
            $rules = array(
                    'username' => 'required|min:3'
            );

            $validator = Validator::make(Input::all(), $rules);

            if ($validator->fails()) {
                    return View::make('user.login')->withErrors($validator);
            }

    }
manavo commented 10 years ago

The errors work when you redirect, and the errors are saved in the session.

To get them to work, you should just be able to change your code to this:

    public function postCreate()
    {
            $rules = array(
                    'username' => 'required|min:3'
            );

            $validator = Validator::make(Input::all(), $rules);

            if ($validator->fails()) {
                    return Redirect::back()->withInput()->withErrors($validator);
            }

    }