-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMenuSection.php
More file actions
91 lines (71 loc) · 2.34 KB
/
MenuSection.php
File metadata and controls
91 lines (71 loc) · 2.34 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace App\Nova;
use App\Models\MenuSection as MenuSectionModel;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Outl1ne\NovaSortable\Traits\HasSortableRows;
class MenuSection extends Resource
{
use HasSortableRows;
public static $group = 'Site';
public static $model = MenuSectionModel::class;
public static $title = 'id';
public static $search = [
'id',
'location',
'column',
'title',
'title_key',
];
public static function label()
{
return 'Menu Sections';
}
public static function singularLabel()
{
return 'Menu Section';
}
public function title(): string
{
$location = (string) ($this->location ?? '');
$column = (string) ($this->column ?? '');
$title = $this->title_key ? __((string) $this->title_key) : (string) ($this->title ?? '');
$title = trim($title) !== '' ? $title : "Section #{$this->id}";
return trim("{$location} · {$column} · {$title}");
}
public function fields(Request $request): array
{
return [
ID::make()->sortable(),
Text::make('Location', 'location')
->rules('required', 'max:255')
->help('Example: resources_dropdown'),
Select::make('Column', 'column')
->options([
'left' => 'Left',
'right' => 'Right',
])
->displayUsingLabels()
->rules('required'),
Text::make('Title Key', 'title_key')
->nullable()
->rules('nullable', 'max:255')
->help('Preferred. Example: menu.learn_to_code'),
Text::make('Title (literal)', 'title')
->nullable()
->rules('nullable', 'max:255')
->help('Used only if Title Key is empty.'),
Boolean::make('Active', 'is_active')->default(true),
HasMany::make('Items', 'items', MenuItem::class),
];
}
public static function indexQuery(NovaRequest $request, $query)
{
return $query->orderBy('sort_order')->orderBy('id');
}
}