Completed
Push — master ( 8503aa...2fe098 )
by
unknown
10:35
created

Locale::label()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BBSLab\NovaTranslation\Resources;
4
5
use BBSLab\NovaTranslation\NovaTranslationServiceProvider;
6
use Illuminate\Http\Request;
7
use Laravel\Nova\Fields\Boolean;
8
use Laravel\Nova\Fields\ID;
9
use Laravel\Nova\Fields\Select;
10
use Laravel\Nova\Fields\Text;
11
use Laravel\Nova\Resource;
12
13
class Locale extends Resource
14
{
15
    /**
16
     * The model the resource corresponds to.
17
     *
18
     * @var string
19
     */
20
    public static $model = 'BBSLab\\NovaTranslation\\Models\\Locale';
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public static $title = 'label';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public static $search = [
31
        'iso',
32
        'label',
33
    ];
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public static $group = null;
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public static function label()
44
    {
45
        return trans(NovaTranslationServiceProvider::PACKAGE_ID.'::lang.locales.resources');
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public static function singularLabel()
52
    {
53
        return trans(NovaTranslationServiceProvider::PACKAGE_ID.'::lang.locales.resource');
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function fields(Request $request)
60
    {
61
        return [
62
            ID::make()->sortable(),
63
64
            Text::make(trans(NovaTranslationServiceProvider::PACKAGE_ID.'::lang.locales.iso'), 'iso')
65
                ->sortable()
66
                ->rules('required', 'max:255')
67
                ->creationRules('unique:locales,iso')
68
                ->updateRules('unique:locales,iso,{{resourceId}}'),
69
70
            Text::make(trans(NovaTranslationServiceProvider::PACKAGE_ID.'::lang.locales.label'), 'label')
71
                ->sortable()
72
                ->rules('required', 'max:255'),
73
74
            Select::make(trans(NovaTranslationServiceProvider::PACKAGE_ID.'::lang.locales.fallback_id'), 'fallback_id')
75
                ->options($this->model()->query()->select('id', 'label')->orderBy('label', 'asc')->get()->pluck('label', 'id')->toArray())
76
                ->nullable()
77
                ->hideFromIndex()
78
                ->displayUsingLabels(),
79
80
            Boolean::make(trans(NovaTranslationServiceProvider::PACKAGE_ID.'::lang.locales.available_in_api'), 'available_in_api'),
81
        ];
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function cards(Request $request)
88
    {
89
        return [];
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function filters(Request $request)
96
    {
97
        return [];
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function lenses(Request $request)
104
    {
105
        return [];
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function actions(Request $request)
112
    {
113
        return [];
114
    }
115
}
116