Skip to content

Commit 3bb5b18

Browse files
authored
Merge pull request #3462 from codeeu/dev
preview on training mode
2 parents f8a80de + ea3e702 commit 3bb5b18

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

app/Http/Controllers/TrainingController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ public function show(string $slug): View
1818
{
1919
$trainingResource = TrainingResource::active()->where('slug', $slug)->firstOrFail();
2020

21-
return view('training.show', compact('trainingResource'));
21+
return view('training.show', [
22+
'trainingResource' => $trainingResource,
23+
'previewMode' => false,
24+
]);
25+
}
26+
27+
public function preview(TrainingResource $trainingResource): View
28+
{
29+
return view('training.show', [
30+
'trainingResource' => $trainingResource,
31+
'previewMode' => true,
32+
]);
2233
}
2334
}

app/Nova/TrainingResource.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Nova;
44

55
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\URL;
67
use Laravel\Nova\Fields\Boolean;
78
use Laravel\Nova\Fields\ID;
89
use Laravel\Nova\Fields\Number;
@@ -45,6 +46,23 @@ public function fields(Request $request): array
4546
->rules('nullable', 'max:255', 'alpha_dash', 'unique:training_resources,slug,{{resourceId}}')
4647
->help('Optional. If empty, generated automatically from title. Used in /training/{slug}.'),
4748

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+
4866
Text::make('Card title', 'card_title')
4967
->rules('nullable', 'max:255')
5068
->help('Optional. Shown in the Learning Bits grid on /training'),
@@ -133,7 +151,8 @@ public function fields(Request $request): array
133151
->help('Lower = shown first among dynamic resources')
134152
->nullable(),
135153

136-
Boolean::make('Active', 'active'),
154+
Boolean::make('Published', 'active')
155+
->help('Turn off to keep this page hidden publicly. Preview URL still works.'),
137156
];
138157
}
139158

resources/views/training/show.blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222

2323
@section('content')
2424
<section id="codeweek-training-dynamic-subpage" class="font-['Blinker'] overflow-hidden">
25+
@if(($previewMode ?? false) === true)
26+
<div class="bg-yellow-100 border-b border-yellow-300 text-[#20262C]">
27+
<div class="codeweek-container-lg py-3 text-sm md:text-base font-medium">
28+
Preview mode: this page is not published yet.
29+
</div>
30+
</div>
31+
@endif
32+
2533
@include('codingathome.banner', [
2634
'author' => $trainingResource->hero_author,
2735
'title' => $displayTitle,

routes/web.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@
339339
'/training/making-and-coding',
340340
[StaticPageController::class, 'static']
341341
)->name('training.module-22'); */
342+
Route::get('/training-preview/{trainingResource}', [TrainingController::class, 'preview'])
343+
->middleware('signed')
344+
->name('training.preview');
342345
Route::get('/training/{slug}', [TrainingController::class, 'show'])->name('training.dynamic.show');
343346
Route::post('/contact-submit', [ContactFormController::class, 'submit'])
344347
->middleware('throttle:5,1') // 5 requests per minute per IP

0 commit comments

Comments
 (0)