Phase 4 work order profile depth

This commit is contained in:
Codex
2026-07-10 13:24:07 -05:00
parent 084b945e75
commit 24fd8c0c5c
21 changed files with 1031 additions and 110 deletions
@@ -71,14 +71,25 @@ class BuyerProfileController extends Controller
'description' => ['nullable', 'string'],
'service_categories' => ['nullable', 'string'],
'hiring_regions' => ['nullable', 'string'],
'hiring_policies_text' => ['nullable', 'string'],
'locations_text' => ['nullable', 'string'],
'vendor_onboarding' => ['nullable', 'string'],
'payment_terms' => ['nullable', 'string'],
'website_url' => ['nullable', 'url', 'max:255'],
'contact_email' => ['nullable', 'email', 'max:255'],
'public_contact' => ['nullable', 'boolean'],
'profile_visibility' => ['nullable', 'array'],
'profile_visibility.*' => ['nullable', 'boolean'],
'private_notes' => ['nullable', 'string'],
]);
$data['public_contact'] = $request->boolean('public_contact');
$data['hiring_policies'] = $this->linesToRecords($data['hiring_policies_text'] ?? '', ['name', 'summary']);
$data['locations'] = $this->linesToRecords($data['locations_text'] ?? '', ['name', 'region']);
$data['profile_visibility'] = $this->normalizeVisibility($request, [
'description', 'categories', 'locations', 'policies', 'payment_terms', 'onboarding',
]);
unset($data['hiring_policies_text'], $data['locations_text']);
$request->user()->buyerProfile()->updateOrCreate(
['user_id' => $request->user()->id],
@@ -94,4 +105,21 @@ class BuyerProfileController extends Controller
'profile' => $buyer->load('user', 'attachments', 'ratings.user'),
]);
}
private function linesToRecords(string $text, array $keys): array
{
return collect(preg_split('/\r\n|\r|\n/', $text))
->map(fn (string $line): array => array_pad(array_map('trim', explode('|', $line, count($keys))), count($keys), null))
->filter(fn (array $parts): bool => (bool) ($parts[0] ?? null))
->map(fn (array $parts): array => collect($keys)->mapWithKeys(fn (string $key, int $index): array => [$key => $parts[$index] ?? null])->all())
->values()
->all();
}
private function normalizeVisibility(Request $request, array $fields): array
{
return collect($fields)
->mapWithKeys(fn (string $field): array => [$field => $request->boolean("profile_visibility.$field")])
->all();
}
}