-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModelLabels.php
47 lines (40 loc) · 868 Bytes
/
ModelLabels.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace SP\Admin\Traits;
use Illuminate\Support\Str;
/**
* Attribute labels.
*
* @package SP\Admin\Traits
*/
trait ModelLabels
{
/**
* List of labels.
* [attribute name => description]
*
* @static
* @return array
*/
public static function attributeLabels(): array
{
return [];
}
/**
* Shows label for the given attribute.
*
* @static
* @param string $attribute Model attribute
* @return string
*/
public static function getAttributeLabel(string $attribute): string
{
$labels = static::attributeLabels();
if (!array_key_exists($attribute, $labels)) {
return Str::title(
str_replace('_', ' ', Str::snake($attribute))
);
}
return $labels[$attribute];
}
}