Skip to content

[5.2] No errors in session after validation fails #12022

@ciliehub

Description

@ciliehub

EDIT! I found the problem >> see second post

I was following Task List, Intermediate Task List and even 'Project Flyer' on Laracasts. There is a problem with displaying errors after a failing validation.

I created a very basic 'contactform', one index/form and one POST with validation. When validation is OK, the behavior is as expected. When validation fails, the errors are not in $errors. I do NOT use authentication, nor a database. I tried it with FormRequest and with basic $request/validation methods.

Besides that, (re)filling forms with value="{{ old('name') }}" also does not work...

And yes, I did put my routes in the web group middleware.

Routes snippet

Route::group(['middleware' => ['web']], function () {
    //Route::resource('contact', 'ContactController');
    Route::get('/contactform', 'ContactController@index');
    Route::post('/contact', 'ContactController@store');
});

Form snippet

@if (count($errors) > 0)
<ul>
        @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
</ul>
@endif

<form action="{{ url('contact') }}" method="POST" class="form-horizontal">
  <input type="text" name="name" id="contact-name" class="form-control">
  <button type="submit">submit</button>
</form>

Controller snippet

public function index(Request $request)
    {
        var_dump($request->session()->all());
        return view('contact.index');
    }

    /**
     * Create a new task.
     *
     * @param  Request $request
     * @return Response
     */
    public function store(Request $request)
    {
        var_dump($request->session()->all());
        $this->validate($request, [
          /* characters will fail the validation */
          'name' => 'required|integer|min:4',
        ]);

        dd($request->all());
    }

correct input gives me the dd() from the store method, so validation is working at a certain level. The problem must be in the redirect and session.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions