Search code examples
phpframeworkslaravelphp-5.3laravel-4

Laravel 4 Form builder Custom Fields Macro


Im trying to create a custom HTML 5 date field for using in a laravel 4 framework view.

{{
    Form::macro('datetime', function($field_name)
    { 
        return '';
    });         
}}

{{ Form::label('event_start', 'Event Date', array('class' => 'control-label')) }}
{{ Form::datetime('event_start') }}

The only problem is the value is not being populated, and i do not know how to do this.

Im using this form to create and edit a model called Event.

how can i populate the value of this field?


Solution

  • Here's what I did:

    in my view I added the following macro

    <?php
    Form::macro('datetime', function($value) {
        return '<input type="datetime" name="my_custom_datetime_field" value="'.$value.'"/>';
    });
    ...
    ...
    // here's how I use the macro and pass a value to it
    {{ Form::datetime($datetime) }}