2020-04-23 00:49:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-04-23 00:49:23 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-04-23 00:49:23 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-04-23 00:49:23 +02:00
|
|
|
*/
|
|
|
|
|
2020-05-02 02:04:25 +02:00
|
|
|
namespace App\Utils\Traits;
|
2020-04-23 00:49:23 +02:00
|
|
|
|
|
|
|
trait WithSorting
|
|
|
|
{
|
|
|
|
public $sort_field = 'id'; // Default sortBy. Feel free to change or pull from client/company settings.
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2020-04-23 00:49:23 +02:00
|
|
|
public $sort_asc = true;
|
|
|
|
|
|
|
|
public function sortBy($field)
|
|
|
|
{
|
|
|
|
$this->sort_field === $field
|
2020-09-06 11:38:10 +02:00
|
|
|
? $this->sort_asc = ! $this->sort_asc
|
2020-04-23 00:49:23 +02:00
|
|
|
: $this->sort_asc = true;
|
|
|
|
|
|
|
|
$this->sort_field = $field;
|
|
|
|
}
|
|
|
|
}
|