Skip to content

Order::driver() uses an inferred foreign key that doesn't exist, so dynamic:driver notifiables never resolve #335

Description

@wespinosar

Summary

Fleetbase\FleetOps\Models\Order::driver() is declared as belongsTo(Driver::class) with no explicit foreign key, so Laravel infers driver_uuid from the method name. The orders table has no such column — the assigned driver is stored in driver_assigned_uuid. $order->driver is therefore always null.

Impact

NotificationRegistry::resolveNotifiable() resolves dynamic:* notifiables through Order::resolveDynamicNotifiable($property), which ends in $this->{$property}. Selecting Dynamic: Driver in Settings → Notifications for any order notification resolves to null, so nobody is notified. The option is present in the UI and silently does nothing.

Versions

Fleetbase v0.7.63 (fleetops v0.6.68); same code in v0.7.58.

Reproduction

$order = Order::whereNotNull('driver_assigned_uuid')->first();
$order->driver;                                       // null
$order->driverAssigned;                               // Driver model
(new Order)->driver()->getForeignKeyName();           // "driver_uuid"
Schema::hasColumn('orders', 'driver_uuid');           // false
Schema::hasColumn('orders', 'driver_assigned_uuid');  // true

Through the UI: Settings → Notifications → Order Dispatched → add "Dynamic: Driver" → dispatch an order that has a driver assigned → no notification is delivered.

Suggested fix

public function driver(): BelongsTo|Builder
{
    return $this->belongsTo(Driver::class, 'driver_assigned_uuid')->without(['devices', 'vendor']);
}

driverAssigned() already works because its method name matches the column.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions