Created
August 20, 2014 12:37
-
-
Save hettiger/cdedc55602274356f2c3 to your computer and use it in GitHub Desktop.
Laravel: Form::selectTime()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Path: app/macros.php (required once in app/start/global.php) | |
Form::macro('selectTime', function($name, $low, $high, $unit, $options = [], $selected = null, $step = 1) | |
{ | |
if ( ! Lang::has('options.' . $unit) ) | |
{ | |
throw new InvalidArgumentException('Failed finding a translation for the provided unit.'); | |
} | |
$timeRange = array(); | |
for ($i = $low; $i <= $high; $i = $i + $step) | |
{ | |
$timeRange[$i] = Lang::choice('options.' . $unit, $i, ['number' => $i]); | |
} | |
return Form::select($name, $timeRange, $selected, $options); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Path: app/lang/en/options.php | |
return array( | |
'days' => ':number day|:number days', | |
'hours' => ':number hour|:number hours', | |
'minutes' => ':number minute|:number minutes', | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment