@php // Pre-populate from a saved campaign on the edit screen ($campaign may // be null on create). All advanced targeting lives in the encrypted // `targeting` array; the JS reads these data-preset JSON blobs to // restore Tom Select state. $tgt = ($campaign ?? null) && is_array($campaign->targeting) ? $campaign->targeting : []; $preset = fn ($k) => json_encode(array_values((array) ($tgt[$k] ?? [])), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); $adv = array_key_exists('advantage_audience', $tgt) ? (int) $tgt['advantage_audience'] : 1; $locTypes = (array) ($tgt['location_types'] ?? []); $budgetLevel = ($campaign->budget_level ?? 'adset'); $bidStrategy = ($campaign->bid_strategy ?? 'LOWEST_COST_WITHOUT_CAP'); $bidAmount = ($campaign->bid_amount ?? null) ? number_format(((int) $campaign->bid_amount) / 100, 2, '.', '') : ''; $specialCats = (array) ($campaign->special_ad_categories ?? []); $fbPos = (array) ($tgt['facebook_positions'] ?? []); $mePos = (array) ($tgt['messenger_positions'] ?? []); $anPos = (array) ($tgt['audience_network_positions'] ?? []); $devs = (array) ($tgt['device_platforms'] ?? []); @endphp