@php $routePrefix = $routePrefix ?? 'admin'; $lookups = $lookups ?? []; $longTextFields = ['description', 'details', 'features', 'admin_note', 'notes', 'instructions', 'body', 'bio', 'skills', 'education', 'experience']; $booleanFields = ['auto_submit', 'refill_enabled', 'dripfeed_enabled']; $dateFields = ['deadline', 'paid_at', 'starts_at', 'ends_at']; $statusOptions = ['active', 'inactive', 'pending', 'queued', 'processing', 'partial', 'assigned', 'in_progress', 'submitted', 'approved', 'revision_required', 'completed', 'published', 'rejected']; $selected = fn ($current, $option): string => (string) $current === (string) $option ? ' selected' : ''; $headline = fn ($value): string => str($value)->replace('_', ' ')->headline()->toString(); $fieldLabel = fn ($field): string => str($field)->replace('_', ' ')->headline()->toString(); $lookupFor = function (string $field) use ($module): string { return match (true) { str_contains($field, 'client_request') => 'requests', str_contains($field, 'payment_method') => 'paymentMethods', str_contains($field, 'gts_service') => 'gtsServices', str_contains($field, 'gts_provider') => 'gtsProviders', str_contains($field, 'gts_wallet') => 'gtsWallets', str_contains($field, 'designer') => 'designers', str_contains($field, 'service') => 'services', str_contains($field, 'plan') => 'plans', default => str_starts_with($module, 'gts-') ? 'gtsClients' : 'clients', }; }; $optionTag = function ($optionValue, string $label, $current) use ($selected): string { return ''.e($label).''; }; $lookupLabel = function ($row): string { if (isset($row->name)) { return (string) $row->name; } if (isset($row->title)) { return (string) $row->title; } $walletOwner = $row->user->name ?? 'Wallet'; $currency = $row->currency ?? 'PKR'; $balance = number_format((float) ($row->balance ?? 0)); return "{$walletOwner} - {$currency} {$balance}"; }; $renderSelect = function (string $field, array $options, $value, $default = null) use ($optionTag): string { $current = $value !== null && $value !== '' ? $value : $default; $html = ''; foreach ($options as $optionValue => $label) { if (is_int($optionValue)) { $optionValue = $label; } $html .= $optionTag($optionValue, (string) $label, $current); } return $html.''; }; $renderField = function (string $field, $value) use ($module, $config, $lookups, $longTextFields, $booleanFields, $dateFields, $statusOptions, $lookupFor, $lookupLabel, $optionTag, $renderSelect, $headline): string { $fieldName = e($field); $safeValue = e($value ?? ''); if (str_ends_with($field, '_id')) { $lookup = $lookupFor($field); $html = 'Select'; foreach (($lookups[$lookup] ?? collect()) as $row) { $html .= $optionTag($row->id, $lookupLabel($row), $value); } return $html.''; } if (in_array($field, $longTextFields, true)) { return ''.$safeValue.''; } if (str_contains($field, 'path') || $field === 'task_file' || array_key_exists($field, $config['files'] ?? [])) { return ''; } if ($field === 'password') { $placeholder = $value ? 'Leave blank to keep current password' : ''; return ''; } if ($field === 'api_key') { $placeholder = $value ? 'Leave blank to keep current API key' : 'Provider API key'; return ''; } if ($field === 'ads_included') { return $renderSelect($field, [1 => 'Ads Included', 0 => 'No Ads'], $value, 1); } if (in_array($field, $booleanFields, true)) { return $renderSelect($field, [1 => 'Enabled', 0 => 'Disabled'], $value, 1); } if ($field === 'type') { return $renderSelect($field, ['credit', 'debit', 'refund', 'adjustment'], $value, 'credit'); } if ($field === 'client_type') { return $renderSelect($field, ['plan' => 'Plan / Monthly Client', 'one_time' => 'One-Time Order Client'], $value, 'plan'); } if ($field === 'progress') { return ''; } if ($field === 'sort_order') { return ''; } if ($field === 'status') { $labels = collect($statusOptions)->mapWithKeys(fn ($option) => [$option => $headline($option)])->all(); return $renderSelect($field, $labels, $value, $module === 'tasks' ? 'pending' : 'active'); } if (in_array($field, $dateFields, true)) { $dateValue = $value instanceof \Carbon\CarbonInterface ? $value->format('Y-m-d') : $value; return ''; } return ''; }; @endphp @csrf @if ($item) @method('PUT') @endif @foreach ($config['fields'] as $field) @php $rawValue = data_get($item, $field); $value = old($field, is_array($rawValue) ? implode("\n", $rawValue) : $rawValue); $isLongText = in_array($field, $longTextFields, true); @endphp {{ $fieldLabel($field) }} {!! $renderField($field, $value) !!} @endforeach Save {{ $config['singular'] }}
Save {{ $config['singular'] }}