dimanche 1 juillet 2018

Laravel 5.6 - Form not re-populating with previous values after validation

I have a simple form in Laravel 5.6 which I am running validation on, my form looks like this..

   @if ($errors->any())
        <div class="alert alert-danger">
            <ul>
                @foreach ($errors->all() as $error)
                    <li></li>
                @endforeach
            </ul>
        </div>
    @endif

<form action="" method="POST">
   <input name="title" type="text">#
    <button type="submit" class="btn btn-success">Submit</button>
</form>

And my controller like this..

public function store(Request $request)
    {

        $this->validate($request, [
            'title' => 'required',
        ]);

        $post = new Post;
        $title = $request->input('title');
        $post->save();
    }

This is working but when the validation fails and the error message is displayed, it does not repopulate the form with the previous values. Reading the docs at https://laravel.com/docs/5.2/requests#old-input it says I shouldn't have to do anything and it will be automatic.

Anyone any ideas where I am going wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire