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

Open Beginner friendly
#335 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend, databases

Research direction

Start with Order::driver() and compare it with driverAssigned(), then trace NotificationRegistry::resolveNotifiable() and Order::resolveDynamicNotifiable($property). Use the provided reproduction and the Settings → Notifications flow to verify that Dynamic: Driver resolves the assigned Driver and delivers the order notification.

Written by the indexing model from the issue text.

Description

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.

Dominant language
PHP
Stars
34
Forks
65
Avg merge
1d 17h
Merged PRs (30d)
31

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fleetbase/fleetops

All issues in fleetbase/fleetops

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.