Files
ladill-care/app/Http/Controllers/Care/OnboardingController.php
T
isaaccladandCursor c3219a1bf1
Deploy Ladill Care / deploy (push) Successful in 36s
Fix nurse onboarding redirects and specialty Documents 404s.
Resolve staff memberships by invite/demo email as well as public_id so nurses stay on their employer org; block staff from owner onboarding; keep Documents viewable with module access while upload stays manage-gated.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-18 19:09:06 +00:00

77 lines
2.9 KiB
PHP

<?php
namespace App\Http\Controllers\Care;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Services\Care\OrganizationResolver;
use App\Services\Care\Workflow\WorkflowTemplateRegistry;
use App\Support\OrganizationBranding;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class OnboardingController extends Controller
{
use ScopesToAccount;
public function __construct(
protected OrganizationResolver $organizations,
protected WorkflowTemplateRegistry $workflows,
) {}
public function show(Request $request): View|RedirectResponse
{
if ($this->organizations->isOnboarded($request->user())) {
return redirect()->route('care.dashboard');
}
if (! $this->organizations->canCompleteOnboarding($request->user())) {
abort(403, 'Your facility setup is incomplete. Ask an administrator to finish onboarding.');
}
return view('care.onboarding.show', [
'user' => $request->user(),
'timezones' => timezone_identifiers_list(),
'categories' => $this->workflows->categories(),
'templates' => $this->workflows->templates(),
'defaultTemplate' => $this->workflows->defaultTemplateKey(),
]);
}
public function store(Request $request): RedirectResponse
{
if ($this->organizations->isOnboarded($request->user())) {
return redirect()->route('care.dashboard');
}
if (! $this->organizations->canCompleteOnboarding($request->user())) {
abort(403, 'Your facility setup is incomplete. Ask an administrator to finish onboarding.');
}
$categoryKeys = array_keys($this->workflows->categories());
$templateKeys = array_keys($this->workflows->templates());
$validated = $request->validate([
'organization_name' => ['required', 'string', 'max:255'],
'facility_category' => ['required', 'string', 'in:'.implode(',', $categoryKeys)],
'workflow_template' => ['required', 'string', 'in:'.implode(',', $templateKeys)],
'branch_name' => ['required', 'string', 'max:255'],
'branch_address' => ['nullable', 'string', 'max:500'],
'branch_phone' => ['nullable', 'string', 'max:50'],
'timezone' => ['required', 'timezone'],
'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'],
]);
$organization = $this->organizations->completeOnboarding($request->user(), $validated);
if ($request->hasFile('logo')) {
$organization->update([
'logo_path' => OrganizationBranding::storeLogo($organization, $request->file('logo')),
]);
}
return redirect()->route('care.dashboard')->with('success', 'Welcome to Ladill Care!');
}
}