Example #1
0
<?php

Form::macro('agegatedate', function ($name, $value = null, $options = array()) {
    switch (Config::get('laravel-avp::input_type')) {
        case 'date':
            if (array_key_exists($name, $value)) {
                $value = $value[$name];
            } else {
                $value = null;
            }
            return Form::agegatehtml5date($name, $value, $options);
        case 'select':
            $names = array($name . '_year', $name . '_month', $name . '_day');
            $value = array_intersect_key($value, array_flip($names));
            return Form::agegateselectsdate($name, $value, $options);
        default:
            throw new InvalidArgumentException('Invalid configuration option for laravel-avp::input_type. Must be one of "date", "select"');
    }
});
Form::macro('agegatehtml5date', 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::macro('agegateselectsdate', function ($name, $value = null, $options = array()) {
    $selectedDay = is_array($value) && array_key_exists($name . '_day', $value) ? $value[$name . '_day'] : false;
    $selectedMonth = is_array($value) && array_key_exists($name . '_month', $value) ? $value[$name . '_month'] : false;
    $selectedYear = is_array($value) && array_key_exists($name . '_year', $value) ? $value[$name . '_year'] : false;