@php
// Helper function to ensure an array is always returned and remove extra quotes
function ensureArray($value) {
if (is_string($value)) {
$decoded = json_decode($value, true);
// If JSON, return decoded array; otherwise, remove extra quotes from the string and wrap in an array
if (is_array($decoded)) {
return array_map(fn($item) => trim($item, '"'), $decoded);
}
return [trim($value, '"')]; // Remove extra quotes if it's a plain string
}
return is_array($value) ? $value : [$value];
}
// Decode JSON fields properly and remove extra quotes
$names = ensureArray($organization['organization_name'] ?? []);
$emails = ensureArray($organization['organization_email'] ?? []);
$phones = ensureArray($organization['organization_phone'] ?? []);
$authorized = ensureArray($organization['organization_authorized_to_sign'] ?? []);
// Get the maximum count of the fields to ensure all rows display correctly
$count = max(count($names), count($emails), count($phones), count($authorized));
@endphp
@for ($i = 0; $i < $count; $i++)
{{ __('Name') }}
{{ __('Email') }}
{{ __('Phone') }}
@if ($i != 0)
{{-- Hide the delete button for the first iteration because the user cannot delete the first member --}}
@endif