techblog/app/Livewire/IncludesSorting.php

21 lines
428 B
PHP
Raw Normal View History

<?php
namespace App\Livewire;
trait IncludesSorting
{
public ?string $sortBy = null;
public string $sortDirection = 'asc';
public function sort(string $column): void
{
if ($this->sortBy === $column) {
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
} else {
$this->sortBy = $column;
$this->sortDirection = 'desc';
}
}
}