我正在编写编辑表单的逻辑,在输入中显示数据时有些复杂.
When I initially show the form, I show the records values like:
value="{{$dog->title}}"
然后,当表单没有通过验证时,我需要显示旧的输入,这样用户就不会丢失他已经输入的内容.所以我需要一种方法来显示旧数据,比如:
value="{{old('title')}}"
因为我需要输入旧数据以防它存在,所以我最终得到了以下代码:
value="{{$dog->title or old('title')}}"
And in controller I check if Request has old input, I assign the $dog var a null value.
I wanted to ask if that is considered an OK practice or is there a better and 'correct' way to do it?