2017-02-28 89 views
2

我想从数据库填充文本字段的值,如果它不等于默认列值。 $event_date的默认列值为'0000-00-00 00:00:00'填充文本提交的值或占位符laravel

如果$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 
+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 
+0

不工作文本字段填充为0000-00-00 00:00:00不使用占位符 –

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> 
+0

它不工作显示相同0000-00-00 00:00:00不占位符 –

+0

请告诉我什么'var_dump ($ conversation-> EVENT_DATE)'? –

+0

var_dump后的字符串(19)“0000-00-00 00:00:00” –