|
3 | 3 | namespace App\Nova; |
4 | 4 |
|
5 | 5 | use Illuminate\Http\Request; |
| 6 | +use Illuminate\Support\Facades\URL; |
6 | 7 | use Laravel\Nova\Fields\Boolean; |
7 | 8 | use Laravel\Nova\Fields\ID; |
8 | 9 | use Laravel\Nova\Fields\Number; |
@@ -45,6 +46,23 @@ public function fields(Request $request): array |
45 | 46 | ->rules('nullable', 'max:255', 'alpha_dash', 'unique:training_resources,slug,{{resourceId}}') |
46 | 47 | ->help('Optional. If empty, generated automatically from title. Used in /training/{slug}.'), |
47 | 48 |
|
| 49 | + Text::make('Preview URL', function () { |
| 50 | + if (! $this->resource?->exists) { |
| 51 | + return 'Save first to generate preview URL.'; |
| 52 | + } |
| 53 | + |
| 54 | + $url = URL::temporarySignedRoute( |
| 55 | + 'training.preview', |
| 56 | + now()->addDays(14), |
| 57 | + ['trainingResource' => $this->resource] |
| 58 | + ); |
| 59 | + |
| 60 | + return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url.'</a>'; |
| 61 | + }) |
| 62 | + ->onlyOnDetail() |
| 63 | + ->asHtml() |
| 64 | + ->help('Share this link with clients for preview before publishing. Link expires in 14 days.'), |
| 65 | + |
48 | 66 | Text::make('Card title', 'card_title') |
49 | 67 | ->rules('nullable', 'max:255') |
50 | 68 | ->help('Optional. Shown in the Learning Bits grid on /training'), |
@@ -133,7 +151,8 @@ public function fields(Request $request): array |
133 | 151 | ->help('Lower = shown first among dynamic resources') |
134 | 152 | ->nullable(), |
135 | 153 |
|
136 | | - Boolean::make('Active', 'active'), |
| 154 | + Boolean::make('Published', 'active') |
| 155 | + ->help('Turn off to keep this page hidden publicly. Preview URL still works.'), |
137 | 156 | ]; |
138 | 157 | } |
139 | 158 |
|
|
0 commit comments