diff --git a/app/Http/Livewire/Traits/WithSort.php b/app/Http/Livewire/Traits/WithSort.php index 854531c..f795fec 100644 --- a/app/Http/Livewire/Traits/WithSort.php +++ b/app/Http/Livewire/Traits/WithSort.php @@ -2,6 +2,8 @@ namespace App\Http\Livewire\Traits; +use Illuminate\Support\Facades\DB; + trait WithSort { /** @@ -45,7 +47,15 @@ trait WithSort { } foreach($columns as $column) { - $query->orderBy($column, $this->dir); + $query->orderBy($this->orderExpr($column), $this->dir); } } + + /** + * Bit of a hack to get nulls to appear last. + */ + private function orderExpr(string $col) : \Illuminate\Database\Query\Expression + { + return DB::raw("ISNULL(`$col`), `$col`"); + } }