schema([ // Purchased phone number (non-editable) TextInput::make('phone_number') ->label('Purchased Phone Number') ->disabled() ->default($this->record->phone_number) ->hint('This is the purchased phone number and cannot be changed'), // Route To number TextInput::make('route_to') ->label('Route To') ->required() ->placeholder('Enter the phone number to route to') ->rules(['phone:US,MX,CA']) ->default($this->record->route_to) ->hint('The phone number to which Twilio will route calls'), // Select type (revenue_code or operational_user) Select::make('type') ->label('Type') ->options([ 'revenue_code' => 'Revenue Code', 'operational_user' => 'Operational User', ]) ->required() ->default($this->record->type) ->reactive(), // Value based on type Select::make('value') ->label('Value') ->options(function (callable $get) { $tenant = auth()->user()->getCurrentTenant(); $clientId = $tenant ? $tenant->id : null; if ($get('type') === 'revenue_code' && $clientId) { return Load::where('client_id', $clientId) ->whereNotNull('revenue_code') ->pluck('revenue_code', 'revenue_code') ->toArray(); } elseif ($get('type') === 'operational_user' && $clientId) { return User::whereHas('clients', function ($query) use ($clientId) { $query->where('client_id', $clientId) ->whereNull('client_user.deleted_at'); }) ->selectRaw("CONCAT(first_name, ' ', last_name) AS full_name, id") ->pluck('full_name', 'id') ->toArray(); } return []; }) ->required() ->default($this->record->value) ->visible(fn(callable $get) => in_array($get('type'), ['revenue_code', 'operational_user'])) ->hint('Select an associated revenue code or operational user'), ]); } }