Define default values for Laravel form fields

前端 未结 7 2145
感动是毒
感动是毒 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:28

    If you want to do this conditionally, an alternative method of solving this could be to perform a check instead. If this check passes, set the default (as is done below with $nom as an example). Otherwise, leave it empty by setting it to null explicitly.

    {{ Form::text('title', (isset($nom)) ? $nom : null) }}
    

提交回复
热议问题