Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Passes the raw array to PHP's
str_starts_with(), which throws:Solution
1. New
ResolvableVehicleRuleAdded
server/src/Rules/ResolvableVehicle.phpthat accepts:public_idstring (e.g.vehicle_abc123)id,public_id, oruuidkey2. Updated
CreateDriverRequestReplaced the brittle string-only rule with the new
ResolvableVehiclerule.3. Normalized input in
DriverControllerAdded normalization in both
createRecordandupdateRecord— 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.phpserver/src/Http/Controllers/Internal/v1/DriverController.php