forked from codestudiohq/laravel-totem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.php
45 lines (38 loc) · 1.14 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Studio\Totem\Helpers;
use Illuminate\Support\HtmlString;
function columnSort(string $label, string $columnKey, bool $isDefault = false)
{
$icon = '';
if (request()->has('sort_by')) {
if (request()->input('sort_by') == $columnKey) {
$icon = ' <span class="fa fa-caret-'
.(request()->input('sort_direction', 'asc') == 'asc' ? 'up' : 'down')
.'"></span>';
}
} elseif ($isDefault) {
$icon = ' <span class="fa fa-caret-'
.(request()->input('sort_direction', 'asc') == 'asc' ? 'up' : 'down')
.'"></span>';
}
$order = 'asc';
if (request()->has('sort_direction')) {
$order = (request()->input('sort_direction') == 'desc' ? 'asc' : 'desc');
} elseif ($isDefault) {
$order = 'desc';
}
$url = request()->fullUrlWithQuery([
'sort_by' => $columnKey,
'sort_direction' => $order,
'filter' => request('filter'),
'limit' => request('limit'),
]);
return new HtmlString(
'<a href="'
.$url
.'">'
.$label
.$icon
.'</a>'
);
}