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');
}
}
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');
}
}
<?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('-'),
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? πŸ™‚
No description
Solution:
I think I solved it with this in the VesselSipAccount model πŸ€·β€β™‚οΈ
No description
Jump to solution
4 Replies
TheRealTeeHill
TheRealTeeHillOPβ€’7mo ago
No description
TheRealTeeHill
TheRealTeeHillOPβ€’7mo ago
Maybe something to do with the null values?
Solution
TheRealTeeHill
TheRealTeeHillβ€’7mo ago
I think I solved it with this in the VesselSipAccount model πŸ€·β€β™‚οΈ
No description
TheRealTeeHill
TheRealTeeHillOPβ€’7mo ago
No description
No description
Want results from more Discord servers?
Add your server