Skip to content

Conversation

@roncodes
Copy link
Member

@roncodes roncodes commented Jan 9, 2026

Problem

The internal was incomplete and missing validation for required fields like , , and . This caused two issues:

  1. Silent failures: Driver creation requests would fail without clear error messages
  2. Missing validation: Drivers could be submitted without required fields through the internal API

The controller extracts data from $request->input('driver') but the validation rules didn't properly validate this nested data.

Solution

Updated server/src/Http/Requests/Internal/CreateDriverRequest.php with:

Required Fields (for creation)

  • name - Driver name (required, max 255 chars)
  • email - Email address (required, must be valid email, unique)
  • phone - Phone number (required, unique)

Optional Fields

  • password - Minimum 8 characters
  • drivers_license_number - Driver's license number
  • internal_id - Internal identifier
  • country - 2-letter country code
  • city - City name
  • vehicle - Vehicle assignment
  • status - active/inactive
  • vendor - Vendor assignment
  • job - Order assignment
  • location, latitude, longitude - Location data
  • photo_uuid, avatar_uuid - Photo uploads

Improvements

  • ✅ Custom error messages for better UX
  • ✅ Custom attribute names for clearer validation errors
  • ✅ Email and phone uniqueness validation
  • ✅ Password minimum length enforcement
  • ✅ Proper validation for all driver form fields

Testing

  • Driver creation now requires name, email, and phone
  • Validation errors are clear and user-friendly
  • Email and phone uniqueness is enforced
  • Optional fields validate correctly when provided
  • UpdateDriverRequest inherits these rules automatically

Impact

  • Onboarding flow: Driver creation during onboarding now works correctly with proper validation
  • Internal API: All internal driver creation requests now have proper validation
  • User experience: Clear error messages when validation fails

Related Issues

Fixes driver creation failures in onboarding flow where users could submit empty forms.

roncodes and others added 7 commits January 9, 2026 02:13
- Add required validation for name, email, and phone fields
- Add validation for drivers_license_number and internal_id
- Add validation for photo_uuid and avatar_uuid
- Add validation for location fields (latitude, longitude)
- Add custom error messages for better UX
- Add custom attribute names for clearer validation errors
- Ensure email and phone uniqueness checks
- Add password minimum length validation (8 characters)

This fixes the issue where drivers could be created without
required fields through the internal API, and improves the
validation error messages shown to users.

Resolves issue where onboarding driver creation was failing
silently due to incomplete validation rules.
- Check if user exists before calling methods on it
- Create new user if user_uuid is provided but user doesn't exist
- Prevents 'Call to a member function companies() on null' error
- Fixes driver creation failure when invalid user_uuid is provided

This resolves the error:
Error: Call to a member function companies() on null
in DriverController.php on line 172
- Changed closure from function($input) to function()
- Use $this->input() to access request data instead
- Fixes ArgumentCountError when Rule::requiredIf evaluates closure
Issue: Users created via driver API were not being tracked in billing system
Root cause: company_uuid was set AFTER user creation via assignCompany()
Solution: Set company_uuid in userDetails BEFORE User::create()

This ensures ResourceCreatedListener can properly track the resource creation
since it requires company_uuid to log usage to billing_resource_usage table.

Without company_uuid at creation time, the listener logs a warning and exits:
'Could not determine company UUID for resource'

Now the flow is:
1. Set company_uuid in userDetails
2. User::create() fires eloquent.created event
3. ResourceCreatedListener receives event with company_uuid
4. Resource usage tracked successfully
…+ fill + save

Issue: Vehicles created via API were not being tracked in billing system
Root cause: Using new Vehicle() + fill() + save() doesn't fire 'created' event
Solution: Replace with Vehicle::create() which properly fires the event

The problem:
- new Vehicle() creates instance
- fill() populates attributes
- save() fires 'updated' event, NOT 'created' event
- ResourceCreatedListener only listens for 'created' event

The fix:
- Vehicle::create($input) fires 'created' event properly
- ResourceCreatedListener receives event with company_uuid
- Resource usage tracked successfully

This is cleaner and more idiomatic Laravel code, and ensures
billing resource tracking works correctly.
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.

2 participants