我正在尝试创建一个自定义 HTML 5 日期字段以在 laravel 4 框架 View 中使用。
{{
Form::macro('datetime', function($field_name)
{
return '';
});
}}
{{ Form::label('event_start', 'Event Date', array('class' => 'control-label')) }}
{{ Form::datetime('event_start') }}
唯一的问题是值没有被填充,我不知道该怎么做。
我使用这个表单来创建和编辑一个名为 Event 的模型。
如何填充此字段的值?
最佳答案
我在 app/start/global.php 中添加了以下内容:
Form::macro('date', function($name, $value = null, $options = array()) {
$input = '<input type="date" name="' . $name . '" value="' . $value . '"';
foreach ($options as $key => $value) {
$input .= ' ' . $key . '="' . $value . '"';
}
$input .= '>';
return $input;
});
但“好方法”是扩展 Form 类并实现您的方法。
关于php - Laravel 4 表单生成器自定义字段宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16259488/