# Blog CTA card: backend changes

**For:** the Laravel CMS team and the website team.
**Status:** the admin panel side is done. Laravel needs one new column (`cta_button_style`) and the website needs to render the card described in §5.
**Date:** 3 November 2026

## 1. Background

Every article on secondlinenumber.com shows a call-to-action card in the right-hand column (see `/blog/best-second-phone-number-apps/`):

```
┌──────────────────────────────┐
│  photo (360 × 260)           │
├──────────────────────────────┤
│  [app icon 50px]             │
│  Need a Second Phone         │   title    Roboto 28/38, weight 800, #000
│  Number? Start Now.          │
│  Stay professional, protect… │   text     Roboto 16/26, #636366
│  [ Download on the App Store]│   Apple badge 160 × 48 → https://apple.co/44uoXf0
└──────────────────────────────┘   light blue panel with contour background, padding 30px
```

The CMS already stores the card's title, description, link, label and image. It has no way to say **"show the App Store badge"** instead of a plain text button, and the live card uses the badge. That is the only missing field.

## 2. What exists today and what's missing

| Piece | Status | Evidence |
| --- | --- | --- |
| `blog_posts.cta_enabled`, `cta_title`, `cta_description`, `cta_button_text`, `cta_button_url`, `cta_image` | ✅ Implemented | Returned by `POST admin/blogs` and `GET admin/blogs` on staging (Postman collection, 2 Nov 2026) |
| Admin save accepts `values.ctaEnabled`, `ctaTitle`, `ctaDescription`, `ctaButtonText`, `ctaButtonUrl`, `ctaImage` | ✅ Implemented | Same |
| Public `GET v1/posts/{slug}` → `cta: { title, description, buttonText, buttonUrl, image }` (null when off or incomplete) | ✅ In the contract | `legacy-postgres/src/features/public-api/queries.ts`. Not checked against staging: public responses are encrypted and no key was available |
| **`cta_button_style`** (`APP_STORE` or `BUTTON`) | ❌ **Missing** | Not in any staging response |
| `cta.buttonStyle` in the public API | ❌ Missing | Depends on the column |
| `ctaButtonStyle` in `admin/settings/blog-defaults` | ❌ Missing (the whole endpoint isn't on staging yet; the admin falls back to built-in defaults) | README "Endpoints Laravel doesn't serve yet" |
| `cta.buttonStyle` in `blog/admin/blogs/import-json` | ❌ Missing | Optional |
| Image alt text for the CTA image | Not needed | The photo is decorative next to the heading; render it with `alt=""` |

### How the admin panel behaves until Laravel adds the column

The admin panel already sends `values.ctaButtonStyle` on every save. Laravel ignores it for now, so:

- When it loads an article, the admin reads `cta_button_style` if present. If it's absent, it **works out the style from the link**: an `apps.apple.com`, `itunes.apple.com` or `apple.co` link means `APP_STORE`, anything else means `BUTTON`.
- This means the badge already works for every article whose link is an App Store link. The only case that doesn't survive a reload is "text button pointing at an App Store link", which is rare.
- Once Laravel stores and returns `cta_button_style`, the admin uses the stored value and no other admin change is needed.

## 3. Laravel changes

Names below follow the existing columns. Adapt class and file names to the CMS codebase.

### 3.1 Migration

```php
<?php
// database/migrations/2026_11_03_000000_add_cta_button_style_to_blog_posts.php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('blog_posts', function (Blueprint $table) {
            $table->string('cta_button_style', 16)->default('BUTTON')->after('cta_button_url');
        });

        // Existing articles that link to the App Store get the badge, as on the live site.
        DB::table('blog_posts')
            ->where(function ($query) {
                $query->where('cta_button_url', 'like', 'https://apps.apple.com/%')
                    ->orWhere('cta_button_url', 'like', 'https://itunes.apple.com/%')
                    ->orWhere('cta_button_url', 'like', 'https://apple.co/%');
            })
            ->update(['cta_button_style' => 'APP_STORE']);
    }

    public function down(): void
    {
        Schema::table('blog_posts', function (Blueprint $table) {
            $table->dropColumn('cta_button_style');
        });
    }
};
```

### 3.2 Enum and model

```php
<?php
// app/Enums/CtaButtonStyle.php

namespace App\Enums;

enum CtaButtonStyle: string
{
    case AppStore = 'APP_STORE';
    case Button = 'BUTTON';
}
```

```php
// app/Models/BlogPost.php
protected $fillable = [
    // …existing fields
    'cta_button_style',
];

protected function casts(): array
{
    return [
        // …existing casts
        'cta_button_style' => \App\Enums\CtaButtonStyle::class,
    ];
}
```

Keep `cta_button_style` in the admin JSON for a blog (it serialises as `"APP_STORE"` / `"BUTTON"`). The admin reads the snake_case key.

### 3.3 Validation (`PUT admin/blogs/{id}` and `POST admin/blogs`)

The admin sends `{ intent, version, values: { …, ctaButtonStyle } }`. Add to the save request's rules:

```php
use App\Enums\CtaButtonStyle;
use Illuminate\Validation\Rule;

'values.ctaButtonStyle' => ['sometimes', 'nullable', Rule::enum(CtaButtonStyle::class)],
```

Add to the **publish/schedule/update** rules (the ones that already require a CTA title, button text and URL when `ctaEnabled` is true):

```php
// A badge must point at the App Store.
if ($values['ctaEnabled'] ?? false) {
    $style = $values['ctaButtonStyle'] ?? 'BUTTON';
    $url   = trim($values['ctaButtonUrl'] ?? '');

    if ($style === 'APP_STORE'
        && ! preg_match('#^https?://(apps\.apple\.com|itunes\.apple\.com|apple\.co)(/|$)#i', $url)) {
        $errors['ctaButtonUrl'] = 'The App Store badge needs an apps.apple.com or apple.co link.';
    }
}
```

Keep `ctaButtonText` required in badge mode. The admin fills it with "Download on the App Store", which the website uses as the link's accessible name, and the public API's "CTA is complete" check stays as it is.

### 3.4 Saving

Wherever the service maps `values` (camelCase) to columns, add one line next to `cta_button_url`:

```php
'cta_button_style' => $values['ctaButtonStyle'] ?? $post->cta_button_style ?? 'BUTTON',
```

It must go through the same three paths as the other CTA fields:

1. **Drafts:** saved straight to the row.
2. **Live and scheduled articles:** autosave parks the whole `values` object in `autosave`. `update` applies it to the row, so `ctaButtonStyle` must be copied with the other CTA fields.
3. **Revisions:** snapshots store the values object. Restoring one must copy `ctaButtonStyle`. Snapshots written before this change have no key: keep the article's current style.

Changing the style counts as a content change, so it should refresh the website cache like any other edit.

### 3.5 Public API (`GET v1/posts/{slug}` and `GET v1/preview/{token}`)

Add `buttonStyle` to the `cta` object:

```json
"cta": {
  "title": "Need a Second Phone Number? Start Now.",
  "description": "Stay professional, protect your privacy, and manage everything from one phone.",
  "buttonText": "Download on the App Store",
  "buttonUrl": "https://apple.co/44uoXf0",
  "buttonStyle": "APP_STORE",
  "image": "https://api.secondlinenumber.com/uploads/2026/02/need-a-second-phone-number.webp"
}
```

- `cta` stays `null` when the CTA is off or the title, button text or URL is empty.
- `image` stays an absolute URL, or `null`.
- Preview responses read the autosave first, as they do for the other fields.
- The field is new, so older website builds ignore it safely.

### 3.6 Blog defaults (`GET`/`PUT admin/settings/blog-defaults`)

When this endpoint is built, accept and return `ctaButtonStyle` next to the other `cta*` defaults. To match the live site, seed:

```json
{
  "ctaEnabled": true,
  "ctaTitle": "Need a Second Phone Number? Start Now.",
  "ctaDescription": "Stay professional, protect your privacy, and manage everything from one phone.",
  "ctaButtonStyle": "APP_STORE",
  "ctaButtonText": "Download on the App Store",
  "ctaButtonUrl": "https://apple.co/44uoXf0",
  "ctaImage": "/uploads/2026/02/need-a-second-phone-number.webp"
}
```

Upload `need-a-second-phone-number.webp` (from `https://secondlinenumber.com/wp-content/uploads/2026/02/`) to the media library first and use the path it returns. The admin's current fallback defaults are "Get Your Number" linking to `/business/phone-numbers`. Product should confirm which one new articles should start with.

### 3.7 JSON import (`blog/admin/blogs/import-json`), optional

Accept `cta.buttonStyle` (`APP_STORE` | `BUTTON`). When it's missing, use the link rule from §2.

## 4. Testing

```bash
# 1. Save a draft with the badge
curl -X POST "$API/admin/blogs" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{
  "intent": "draft",
  "values": {
    "title": "CTA style test",
    "content": "<p>Test</p>",
    "ctaEnabled": true,
    "ctaTitle": "Need a Second Phone Number? Start Now.",
    "ctaButtonText": "Download on the App Store",
    "ctaButtonUrl": "https://apple.co/44uoXf0",
    "ctaButtonStyle": "APP_STORE"
  }
}'
# → data.cta_button_style == "APP_STORE"

# 2. Bad value
#    "ctaButtonStyle": "BANNER"  → 422 on values.ctaButtonStyle

# 3. Publishing a badge with a non-Apple link
#    "ctaButtonStyle": "APP_STORE", "ctaButtonUrl": "/pricing/", intent "publish"
#    → 422 on ctaButtonUrl

# 4. Public API after publishing
npm run laravel -- public post cta-style-test   # (admin repo) → cta.buttonStyle == "APP_STORE"
```

Also check:

- [ ] A live article: change the style, autosave, then **Update**. The public API changes only after Update.
- [ ] Restore an older revision: the style comes back with it.
- [ ] After the migration, existing articles with an apple.co link return `APP_STORE`.

## 5. Website rendering (website repository)

Render the card from `post.cta` in the article sidebar. These values come from the live Elementor template (`post-1920.css`):

| | Desktop (wider than 992px) | Tablets and phones (992px and narrower) |
| --- | --- | --- |
| Position | Right column (48% wide; 43% up to 1441px), sticky, 110px from the top | After the article, full width (the row wraps) |
| Order | Image, then panel | Panel, then image (`flex-direction: column-reverse`) |
| Corners | 10px. Image rounded on top, panel on the bottom | Swapped |
| Panel | Background `cta-bg.webp` (light blue contour lines), padding 30px (25px up to 1441px), gap 15px | Padding 20px |
| App icon | `secondphone-icon.svg`, 50px (15% of the panel up to 1180px) | 60px |
| Title | `<h2>`, Roboto 28px/38px, weight 800, `#000` (24/34 up to 1441px) | 24/34 |
| Description | Roboto 16px/26px, `#636366`, −12px top margin (15px up to 1441px) | 15px |
| Badge (`APP_STORE`) | Apple's official "Download on the App Store" artwork, 160 × 48 (120px wide up to 1180px). `<a href={buttonUrl} target="_blank" rel="noopener" aria-label={buttonText}>` | 120px wide |
| Button (`BUTTON`) | Brand blue `#0084FF`, white bold text plus an arrow, 48px tall, 8px corners, `<a href={buttonUrl}>{buttonText}</a>` | Same |
| Image | `image` at 360 × 260 (upload 720 × 520 for sharp screens), `object-fit: cover`, `alt=""`, `loading="lazy"` | Full width, same ratio |

If `image` is null, show the panel alone with all corners rounded. If `buttonStyle` is missing (an older API), treat it as `BUTTON`, or apply the App Store link rule from §2.

## 6. Admin panel changes already made (for reference)

- `src/features/blogs/schemas.ts`: `ctaButtonStyle` value, the App Store link rule, and a publish check that a badge points at the App Store.
- `src/features/blogs/service.ts`: reads `cta_button_style`, falling back to the link rule.
- `src/features/blogs/editor/cta-section.tsx`: redesigned editor. Choose badge or text button, a one-click app link, 720 × 520 image guidance, and a live preview of the website card at desktop and phone sizes.
- `src/features/blogs/markdown-import.ts`: front matter `cta: { style: app_store }` or `cta_style`.
