2017-12-20 10:19:36 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by IntelliJ IDEA.
|
|
|
|
* User: nshahzad
|
|
|
|
* Date: 12/19/17
|
|
|
|
* Time: 8:04 PM
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models\Enums;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class EnumBase
|
|
|
|
* @package App\Models\Enums
|
|
|
|
*/
|
|
|
|
class EnumBase
|
|
|
|
{
|
|
|
|
protected static $labels = [];
|
2017-12-21 03:27:57 +08:00
|
|
|
protected static $adverbs = [];
|
2017-12-20 10:19:36 +08:00
|
|
|
|
|
|
|
/**
|
2017-12-21 03:27:57 +08:00
|
|
|
* Return the label, try to return the translated version as well
|
2017-12-20 10:19:36 +08:00
|
|
|
* @param $value
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public static function label($value) {
|
2017-12-21 03:27:57 +08:00
|
|
|
if(isset(static::$labels[$value])) {
|
|
|
|
return trans(static::$labels[$value]);
|
|
|
|
}
|
2017-12-20 10:19:36 +08:00
|
|
|
}
|
2017-12-23 06:32:21 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all of the (translated) labels
|
|
|
|
*/
|
|
|
|
public static function labels()
|
|
|
|
{
|
|
|
|
$labels = [];
|
|
|
|
foreach(static::$labels as $key => $label) {
|
|
|
|
$labels[$key] = trans($label);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $labels;
|
|
|
|
}
|
2018-01-01 04:00:50 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Select box
|
|
|
|
*/
|
|
|
|
public static function select($add_blank=false)
|
|
|
|
{
|
|
|
|
$labels = [];
|
|
|
|
if($add_blank) {
|
|
|
|
$labels[] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (static::$labels as $key => $label) {
|
|
|
|
$labels[$key] = trans($label);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $labels;
|
|
|
|
}
|
2017-12-20 10:19:36 +08:00
|
|
|
}
|