Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/Http/Controllers/TrainingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ public function show(string $slug): View
{
$trainingResource = TrainingResource::active()->where('slug', $slug)->firstOrFail();

return view('training.show', compact('trainingResource'));
return view('training.show', [
'trainingResource' => $trainingResource,
'previewMode' => false,
]);
}

public function preview(TrainingResource $trainingResource): View
{
return view('training.show', [
'trainingResource' => $trainingResource,
'previewMode' => true,
]);
}
}
21 changes: 20 additions & 1 deletion app/Nova/TrainingResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -45,6 +46,23 @@ public function fields(Request $request): array
->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'),
Expand Down Expand Up @@ -133,7 +151,8 @@ public function fields(Request $request): array
->help('Lower = shown first among dynamic resources')
->nullable(),

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

Expand Down
8 changes: 8 additions & 0 deletions resources/views/training/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

@section('content')
<section id="codeweek-training-dynamic-subpage" class="font-['Blinker'] overflow-hidden">
@if(($previewMode ?? false) === true)
<div class="bg-yellow-100 border-b border-yellow-300 text-[#20262C]">
<div class="codeweek-container-lg py-3 text-sm md:text-base font-medium">
Preview mode: this page is not published yet.
</div>
</div>
@endif

@include('codingathome.banner', [
'author' => $trainingResource->hero_author,
'title' => $displayTitle,
Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@
'/training/making-and-coding',
[StaticPageController::class, 'static']
)->name('training.module-22'); */
Route::get('/training-preview/{trainingResource}', [TrainingController::class, 'preview'])
->middleware('signed')
->name('training.preview');
Route::get('/training/{slug}', [TrainingController::class, 'show'])->name('training.dynamic.show');
Route::post('/contact-submit', [ContactFormController::class, 'submit'])
->middleware('throttle:5,1') // 5 requests per minute per IP
Expand Down
Loading