From 6731b4c487c11b650937f6c8066bdbcfc4b5bd79 Mon Sep 17 00:00:00 2001 From: jon brookes Date: Sat, 17 Jan 2026 16:35:14 +0000 Subject: [PATCH] added url and call to action to entries migraiton and model updated unit tests --- .../Resources/Entries/Schemas/EntryForm.php | 29 +++++++++++-------- app/Http/Resources/EntryResource.php | 2 ++ app/Models/Entry.php | 4 ++- .../2026_01_17_162204_add-url-to-entries.php | 29 +++++++++++++++++++ tests/Unit/EntryModelTest.php | 3 +- 5 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 database/migrations/2026_01_17_162204_add-url-to-entries.php diff --git a/app/Filament/Resources/Entries/Schemas/EntryForm.php b/app/Filament/Resources/Entries/Schemas/EntryForm.php index 573a47a..7f2be7c 100644 --- a/app/Filament/Resources/Entries/Schemas/EntryForm.php +++ b/app/Filament/Resources/Entries/Schemas/EntryForm.php @@ -67,11 +67,11 @@ class EntryForm $fileName = e($item->file_name); $name = e($item->name ?? ''); - $html = "
". - "{$fileName}". - "
". - "{$name}". - "{$fileName}". + $html = "
" . + "{$fileName}" . + "
" . + "{$name}" . + "{$fileName}" . '
'; return [$item->id => $html]; @@ -111,7 +111,7 @@ class EntryForm } $sourceFile = $sourceMedia->getPath(); - $tempCopy = sys_get_temp_dir().'/'.uniqid().'_'.$sourceMedia->file_name; + $tempCopy = sys_get_temp_dir() . '/' . uniqid() . '_' . $sourceMedia->file_name; copy($sourceFile, $tempCopy); try { @@ -141,7 +141,7 @@ class EntryForm } catch (\Exception $e) { \Filament\Notifications\Notification::make() ->danger() - ->title('Error: '.$e->getMessage()) + ->title('Error: ' . $e->getMessage()) ->send(); } finally { if (file_exists($tempCopy)) { @@ -163,6 +163,11 @@ class EntryForm ->toArray(); }) ->searchable(), + TextInput::make('call_to_action_text') + ->label('Call to Action Text'), + TextInput::make('call_to_action_link') + ->label('Call to Action URL'), + RichEditor::make('content') ->columnSpanFull() ->hintAction( @@ -193,11 +198,11 @@ class EntryForm $name = e($item->name ?? ''); // Smaller image preview for better performance - $html = "
". - "{$fileName}". - "
". - "{$name}". - "{$fileName}". + $html = "
" . + "{$fileName}" . + "
" . + "{$name}" . + "{$fileName}" . '
'; return [$url => $html]; diff --git a/app/Http/Resources/EntryResource.php b/app/Http/Resources/EntryResource.php index e674d9a..a116de1 100644 --- a/app/Http/Resources/EntryResource.php +++ b/app/Http/Resources/EntryResource.php @@ -25,6 +25,8 @@ class EntryResource extends JsonResource 'content' => $this->content, 'category' => $this->category->name ?? null, 'featured_image_url' => $this->getFirstMediaUrl('featured-image') ?: null, + 'call_to_action_text' => $this->call_to_action_text, + 'call_to_action_link' => $this->call_to_action_link, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]; diff --git a/app/Models/Entry.php b/app/Models/Entry.php index cc4822f..476e4b5 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -17,6 +17,7 @@ use Spatie\Tags\HasTags; Entry model with rich content and media library integration This is the main article / blog rich content model */ + class Entry extends Model implements HasMedia, HasRichContent { use HasFactory, HasTags, InteractsWithMedia, InteractsWithRichContent; @@ -29,7 +30,8 @@ class Entry extends Model implements HasMedia, HasRichContent 'is_featured', 'published_at', 'content', - 'category_id', + 'call_to_action_link', + 'call_to_action_text', ]; /** diff --git a/database/migrations/2026_01_17_162204_add-url-to-entries.php b/database/migrations/2026_01_17_162204_add-url-to-entries.php new file mode 100644 index 0000000..f40244e --- /dev/null +++ b/database/migrations/2026_01_17_162204_add-url-to-entries.php @@ -0,0 +1,29 @@ +string('call_to_action_text')->nullable()->after('title'); + $table->string('call_to_action_link')->nullable()->after('url'); + }); + } + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('entries', function (Blueprint $table) { + $table->dropColumn('call_to_action_text'); + $table->dropColumn('call_to_action_link'); + }); + } +}; diff --git a/tests/Unit/EntryModelTest.php b/tests/Unit/EntryModelTest.php index 37fa5a6..3085db9 100644 --- a/tests/Unit/EntryModelTest.php +++ b/tests/Unit/EntryModelTest.php @@ -11,7 +11,8 @@ it('has correct fillable attributes', function () { 'is_featured', 'published_at', 'content', - 'category_id', + 'call_to_action_link', + 'call_to_action_text', ]; $entry = new Entry;