What is the best practice to show old value when editing a form in Laravel?

前端 未结 6 1069
暗喜
暗喜 2021-02-01 03:04

I am writing the logic for an edit form and have some complications when displaying data in the inputs.

When I initially show the form, I show the records values like:

6条回答
  •  时光说笑
    2021-02-01 03:46

    Another way to do that is get the data from the dog class, like this:

    value="{{old('title') ?? $dog->title }}"
    

    Why? Because old() is for validation; when you fail validation, the input will remain available in the field. In the case where validation hasn't fired yet, value will be filled with $dog->title.

提交回复
热议问题