-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTrainingResource.php
More file actions
163 lines (124 loc) · 5.72 KB
/
TrainingResource.php
File metadata and controls
163 lines (124 loc) · 5.72 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace App\Nova;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Fields\Trix;
use Laravel\Nova\Http\Requests\NovaRequest;
class TrainingResource extends Resource
{
public static $group = 'Resources';
public static $model = \App\TrainingResource::class;
public static $title = 'card_title';
public static $search = ['slug', 'card_title', 'page_title', 'card_author'];
public static function label()
{
return 'Training Resources';
}
public static function singularLabel()
{
return 'Training Resource';
}
public static function authorizedToViewAny(Request $request): bool
{
return true;
}
public function fields(Request $request): array
{
return [
ID::make()->sortable(),
Text::make('Slug', 'slug')
->rules('nullable', 'max:255', 'alpha_dash', 'unique:training_resources,slug,{{resourceId}}')
->help('Optional. If empty, generated automatically from title. Used in /training/{slug}.'),
Text::make('Preview URL', function () {
if (! $this->resource?->exists) {
return 'Save first to generate preview URL.';
}
$url = URL::temporarySignedRoute(
'training.preview',
now()->addDays(14),
['trainingResource' => $this->resource]
);
return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url.'</a>';
})
->onlyOnDetail()
->asHtml()
->help('Share this link with clients for preview before publishing. Link expires in 14 days.'),
Text::make('Card title', 'card_title')
->rules('nullable', 'max:255')
->help('Optional. Shown in the Learning Bits grid on /training'),
Text::make('Card author', 'card_author')
->nullable()
->help('Optional subtitle shown under the card title'),
Text::make('Card image', 'card_image')
->nullable()
->help('Supports full URLs (including Amazon S3/CloudFront) or local paths like /img/learning/my-image.png. Plain filenames are treated as /img/learning/{filename}.'),
Text::make('Page title', 'page_title')->rules('nullable', 'max:255')
->help('Optional. Falls back to card title.'),
Text::make('Hero author', 'hero_author')
->nullable()
->help('Optional pill text in the header banner'),
Trix::make('Intro', 'intro')
->nullable()
->help('Optional intro block shown above the main content'),
Trix::make('Highlight box', 'highlight_box')
->nullable()
->help('Optional styled gray section (e.g. Scientific author / Contributors block).'),
Text::make('Video URL', 'video_url')
->nullable()
->help('Optional YouTube URL. Supports youtu.be, watch, embed, shorts.'),
Text::make('Video script URL', 'video_script_url')
->nullable()
->rules('nullable', 'url')
->help('Optional link shown under the video, e.g. DOCX/PDF script.'),
Text::make('Video script link text', 'video_script_text')
->nullable()
->help('Optional. Defaults to "Download the video script".'),
Text::make('Body image', 'body_image')
->nullable()
->help('Optional image path/URL (supports Amazon S3/CloudFront).'),
Text::make('Body image alt text', 'body_image_alt')
->nullable(),
Trix::make('Content', 'content')
->nullable()
->help('Main training content area'),
Trix::make('PDF links section', 'pdf_links_section')
->nullable()
->help('Optional area for numbered downloadable resources (e.g. 1-6 links).'),
Trix::make('Contacts section', 'contacts_section')
->nullable()
->help('Optional contacts/extra info block.'),
Trix::make('Register box section', 'register_box_section')
->nullable()
->help('Optional text shown in a highlighted callout box (register on map, hashtags, etc).'),
Text::make('Button text', 'button_text')->nullable(),
Text::make('Button URL', 'button_url')
->nullable()
->rules('nullable', 'url'),
Text::make('Secondary button text', 'secondary_button_text')->nullable(),
Text::make('Secondary button URL', 'secondary_button_url')
->nullable()
->rules('nullable', 'url'),
Text::make('Meta title', 'meta_title')
->nullable()
->help('Optional HTML title override'),
Textarea::make('Meta description', 'meta_description')
->nullable()
->alwaysShow(),
Number::make('Position', 'position')
->min(0)
->help('Lower = shown first among dynamic resources')
->nullable(),
Boolean::make('Published', 'active')
->help('Turn off to keep this page hidden publicly. Preview URL still works.'),
];
}
public static function indexQuery(NovaRequest $request, $query)
{
return $query->orderBy('position')->orderBy('created_at', 'desc');
}
}