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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions app/Http/Controllers/TrainingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Controllers;

use App\TrainingResource;
use Illuminate\View\View;

class TrainingController extends Controller
{
public function index(): View
{
$dynamicTrainingResources = TrainingResource::active()->ordered()->get();

return view('static.training.index', compact('dynamicTrainingResources'));
}

public function show(string $slug): View
{
$trainingResource = TrainingResource::active()->where('slug', $slug)->firstOrFail();

return view('training.show', compact('trainingResource'));
}
}
123 changes: 123 additions & 0 deletions app/Nova/TrainingResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

namespace App\Nova;

use Illuminate\Http\Request;
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('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('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'),

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('Active', 'active'),
];
}

public static function indexQuery(NovaRequest $request, $query)
{
return $query->orderBy('position')->orderBy('created_at', 'desc');
}
}
144 changes: 144 additions & 0 deletions app/TrainingResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class TrainingResource extends Model
{
use HasFactory;

protected $fillable = [
'slug',
'card_title',
'card_author',
'card_image',
'page_title',
'hero_author',
'intro',
'highlight_box',
'video_url',
'body_image',
'body_image_alt',
'content',
'button_text',
'button_url',
'secondary_button_text',
'secondary_button_url',
'meta_title',
'meta_description',
'position',
'active',
];

protected $casts = [
'active' => 'boolean',
'position' => 'integer',
];

public function scopeActive($query)
{
return $query->where('active', true);
}

public function scopeOrdered($query)
{
return $query->orderBy('position')->orderBy('created_at', 'desc');
}

public function getRouteKeyName(): string
{
return 'slug';
}

protected static function booted(): void
{
static::saving(function (self $resource) {
if (blank($resource->slug)) {
$baseSlug = Str::slug($resource->card_title ?: $resource->page_title ?: 'training-resource');
$resource->slug = $resource->generateUniqueSlug($baseSlug ?: 'training-resource');
}

if (blank($resource->card_title)) {
$resource->card_title = $resource->page_title ?: Str::headline($resource->slug);
}

if (blank($resource->page_title)) {
$resource->page_title = $resource->card_title;
}
});
}

protected function generateUniqueSlug(string $baseSlug): string
{
$slug = $baseSlug;
$counter = 1;

while (self::query()
->where('slug', $slug)
->when($this->exists, fn ($query) => $query->where('id', '!=', $this->id))
->exists()) {
$slug = $baseSlug.'-'.$counter;
$counter++;
}

return $slug;
}

public function getResolvedCardImageAttribute(): string
{
$image = trim((string) $this->card_image);

if ($image === '') {
return '/img/learning/cody-color-kit.png';
}

// Allow absolute URLs (including Amazon S3/CloudFront), protocol-relative, or root-relative paths.
if (Str::startsWith($image, ['http://', 'https://', '//', '/'])) {
return $image;
}

// Backward-compatible shorthand: treat plain filenames as /img/learning/{filename}.
return '/img/learning/'.$image;
}

public function getResolvedBodyImageAttribute(): ?string
{
$image = trim((string) $this->body_image);

if ($image === '') {
return null;
}

if (Str::startsWith($image, ['http://', 'https://', '//', '/'])) {
return $image;
}

return '/img/learning/'.$image;
}

public function getYoutubeVideoIdAttribute(): ?string
{
$url = trim((string) $this->video_url);
if ($url === '') {
return null;
}

$patterns = [
'/youtu\.be\/([a-zA-Z0-9_-]{11})/i',
'/youtube\.com\/watch\?v=([a-zA-Z0-9_-]{11})/i',
'/youtube\.com\/embed\/([a-zA-Z0-9_-]{11})/i',
'/youtube\.com\/shorts\/([a-zA-Z0-9_-]{11})/i',
];

foreach ($patterns as $pattern) {
if (preg_match($pattern, $url, $matches) === 1) {
return $matches[1];
}
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('training_resources', function (Blueprint $table) {
$table->id();
$table->string('slug')->unique();
$table->string('card_title');
$table->string('card_author')->nullable();
$table->string('card_image')->nullable();
$table->string('page_title');
$table->string('hero_author')->nullable();
$table->longText('intro')->nullable();
$table->longText('content')->nullable();
$table->string('button_text')->nullable();
$table->string('button_url')->nullable();
$table->string('meta_title')->nullable();
$table->text('meta_description')->nullable();
$table->unsignedInteger('position')->default(0)->nullable();
$table->boolean('active')->default(true);
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('training_resources');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('training_resources', function (Blueprint $table) {
$table->longText('highlight_box')->nullable()->after('intro');
$table->string('video_url')->nullable()->after('highlight_box');
$table->string('body_image')->nullable()->after('video_url');
$table->string('body_image_alt')->nullable()->after('body_image');
$table->string('secondary_button_text')->nullable()->after('button_url');
$table->string('secondary_button_url')->nullable()->after('secondary_button_text');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('training_resources', function (Blueprint $table) {
$table->dropColumn([
'highlight_box',
'video_url',
'body_image',
'body_image_alt',
'secondary_button_text',
'secondary_button_url',
]);
});
}
};
Loading
Loading