Laravel blade “old input or default variable”?

后端 未结 4 1952
执笔经年
执笔经年 2021-02-06 22:30

I want to show the old input in input value. If there isn\'t old input, than show other variable:

value=\"{{ old(\'salary_\' . $employee->id) or \'Default\' }         


        
4条回答
  •  一个人的身影
    2021-02-06 22:45

    You can use the code (for PHP 7):

    {{ old('field_name') ?? $model->field_name ?? 'default' }}
    

    For checkbox checked attribute use the code (if default value is false):

    {{ (old() ? old('field_name', false) : $model->field_name ?? false) ? 'checked' : '' }}
    

    Construction {{ $something or 'default'}} works only for variables

提交回复
热议问题