Define default values for Laravel form fields

前端 未结 7 2098
感动是毒
感动是毒 2021-02-20 12:45

To pre-populate form field, we can add \'value\' to form field in create.blade.php:

{{ Form::text(\'title\', \'Some default title\') }}

Is ther

相关标签:
7条回答
  • 2021-02-20 13:31

    Probably easier (Laravel 5):

    {{ Form::text('title', isset($yourModel) ? null : 'Some default title') }}
    

    That is to assume you are using the form as a partial. It should populate the value if the model for the form exists (you are editing or patching record) else it should show you the default you wish.

    0 讨论(0)
提交回复
热议问题