@php $optionsFor = fn (string $type) => match ($type) { 'product' => $products, 'colour' => $colours, 'tier' => $tiers, 'campaign' => $campaignsList, 'reward' => $rewards, 'bool' => ['1' => 'Yes', '0' => 'No'], default => null, }; @endphp

{{ $campaignId ? 'Edit campaign' : 'New campaign' }}

Campaigns / {{ $form['name'] ?: 'Untitled' }}
{{-- WHEN --}}
1 · When
{{-- IF --}}
2 · Only if (all must match)
@forelse ($conditions as $i => $c) @php $type = $fields[$c['field']][1] ?? 'text'; $opts = $optionsFor($type); @endphp
@if (in_array($c['field'], ['has_tag', 'not_tag', 'member_of', 'marketing_opt_in'], true)) {{ $c['field'] === 'not_tag' ? 'is not' : 'is' }} @else @endif @if ($opts) @else @endif
@empty

No conditions — runs for everyone on this trigger (still once per customer per event).

@endforelse
{{-- THEN --}}
3 · Then (in order)
@error('actions'){{ $message }}@enderror @foreach ($actions as $i => $a) @php $action = \App\Services\Automation\CampaignEngine::action($a['type']); @endphp
{{ $i + 1 }}
@foreach ($action?->fields() ?? [] as $name => $def) @php [$label, $ftype] = $def; $model = "actions.{$i}.params.{$name}"; @endphp @if ($ftype === 'textarea')
@elseif ($ftype === 'bool')
@elseif (str_starts_with($ftype, 'select:')) @elseif ($opts = $optionsFor($ftype)) @else @endif @endforeach
@endforeach

Merge fields for emails and messages: {first_name} {name} {order_number} {order_total} {points} {coupon_code} {coupon_value} {coupon_expires} {reward} {reward_code} {colour} {challenge} {creator_code} {cart_items} {cart_subtotal} {cart_products} {store_name}. Actions earlier in the list can fill later ones (e.g. create a coupon, then email {coupon_code}).