Skip to content

fix: Resolve vehicle from uuid, public_id, or object when creating/updating driver#209

Merged
roncodes merged 3 commits intomainfrom
fix/driver-vehicle-validation-error
Feb 28, 2026
Merged

fix: Resolve vehicle from uuid, public_id, or object when creating/updating driver#209
roncodes merged 3 commits intomainfrom
fix/driver-vehicle-validation-error

Conversation

@roncodes
Copy link
Member

@roncodes roncodes commented Feb 28, 2026

Problem

Reported in issue: fleetbase/fleetbase#507

When creating or updating a driver with a vehicle assigned, the frontend sends the vehicle as a full object payload (e.g. {id: "vehicle_abc", name: "...", make: "..."}) rather than a plain string public ID.

The existing validation rule:

'vehicle' => 'nullable|string|starts_with:vehicle_|exists:vehicles,public_id'

Passes the raw array to PHP's str_starts_with(), which throws:

TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, array given

Solution

1. New ResolvableVehicle Rule

Added server/src/Rules/ResolvableVehicle.php that accepts:

  • A public_id string (e.g. vehicle_abc123)
  • A UUID string
  • An array/object containing an id, public_id, or uuid key

2. Updated CreateDriverRequest

Replaced the brittle string-only rule with the new ResolvableVehicle rule.

3. Normalized input in DriverController

Added normalization in both createRecord and updateRecord — if the vehicle field is an array, it extracts the identifier before validation runs.

Files Changed

  • server/src/Rules/ResolvableVehicle.php (new)
  • server/src/Http/Requests/CreateDriverRequest.php
  • server/src/Http/Controllers/Internal/v1/DriverController.php

roncodes and others added 3 commits February 27, 2026 19:56
…dating driver

- Add ResolvableVehicle validation rule that accepts a vehicle public_id
  string, UUID string, or an array/object with id/public_id/uuid key
- Update CreateDriverRequest to use ResolvableVehicle rule instead of
  the previous string-only validation which threw a TypeError when the
  frontend sent the full vehicle object
- Normalize vehicle input in DriverController createRecord and updateRecord
  before validation so array payloads are reduced to a string identifier

Fixes: TypeError: str_starts_with(): Argument #1 ($haystack) must be of
type string, array given
…uest

The API CreateDriverRequest (consumable API) must always require a vehicle
public_id string - this is intentional and correct.

The Internal CreateDriverRequest is what the console frontend uses, and it
sends the full vehicle object from Ember Data. Apply ResolvableVehicle rule
only to the internal request so it accepts uuid, public_id string, or object.
@roncodes roncodes merged commit 071a0f0 into main Feb 28, 2026
4 checks passed
@roncodes roncodes deleted the fix/driver-vehicle-validation-error branch February 28, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant