使用值或占位符laravel填充文本

时间:2017-02-28 10:53:37

标签: php laravel laravel-5 laravel-5.2 laravel-blade

如果它不等于默认列值,我想用数据填充数据库中的文本字段。我$event_date的默认列值为'0000-00-00 00:00:00'

如果$event_date='0000-00-00 00:00:00',那么我想使用占位符Date

@if($conversation->event_date!='0000-00-00 00:00:00')
  <div class="form-group">
   {{ Form::text('event_date', null, array('class' => 'form-control
   conversation-field')) }}
  </div>
 @else
  <div class="form-group">
   {{ Form::text('event_date', null, array('class' => 'form-control 
   conversation-field','placeholder'=>'Date')) }}
  </div>
 @endif

2 个答案:

答案 0 :(得分:0)

输出HTML内容时你不应该逃避{!!而不是{{

@if ($conversation->event_date != '0000-00-00 00:00:00')
  <div class="form-group">
   {!! Form::text('event_date', $conversation->event_date, array('class' => 'form-control
   conversation-field')) !!}
  </div>
 @else
  <div class="form-group">
   {!! Form::text('event_date', null, array('class' => 'form-control 
   conversation-field','placeholder'=>'Date')) !!}
  </div>
 @endif

答案 1 :(得分:0)

以简单而又简洁的方式执行此类操作:

  <div class="form-group">
   {{ Form::text('event_date', $conversation->event_date != '0000-00-00 00:00:00' ? $conversation->event_date : null, array('class' => 'form-control
   conversation-field', 'placeholder'=>'Date')) }}
  </div>