Sortable() on One-of-Many column not sorting properly

I have a VesselSipAccount
class VesselSipAccount extends Model
{
    use HasFactory;

    protected $fillable = [
        'username',
        'password',
        'full_name',
        'phone_number',
        'location',
        'is_vsat',
        'device_id',
        'api_hash',
        'collect_status_logs',
        'collect_call_logs',
        'vessel_id',
    ];

    public function vessel()
    {
        return $this->belongsTo(Vessel::class, 'vessel_id');
    }

    public function statuses()
    {
        return $this->hasMany(VesselSipAccountNetworkStatus::class, 'vessel_sip_account_id');
    }

    public function latestStatus()
    {
        return $this->statuses()->one()->ofMany('created_at', 'max');
    }
}

and a VesselSipAccountStatus
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class VesselSipAccountNetworkStatus extends Model
{
    use HasFactory;

    protected $fillable = [
        'public_ip',
        'local_ip',
        'status',
        'latency',
        'vessel_sip_account_id',
    ];

    public function sipAccount()
    {
        return $this->belongsTo(VesselSipAccount::class, 'vessel_sip_account_id');
    }
}

and a column in the VesselSipAccountResource
Tables\Columns\TextColumn::make('latestStatus.local_ip')->label('Local IP')->sortable()->searchable()->default('-'),

The data loads fine but when I sort by the column it doesn't sort properly, and I noticed that sorting again to change to desc the order does not change. Any ideas? πŸ™‚
image.png
Solution
I think I solved it with this in the VesselSipAccount model πŸ€·β€β™‚οΈ
IMG_1227.jpg
Was this page helpful?