Define default values for Laravel form fields

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

    All you need to do is include a conditional in your blade template.

    Lets assume your database table has a field myfield, which you want to default to mydefault.

    Just include the following in a partial view which is called by the create and edit views:

    @if(isset($myfield))
    {{ Form::input('text','myfield') }}
    @else
    {{ Form::input('text','myfield','mydefault') }}
    @endif
    

    You don't have to anything else.

提交回复
热议问题