-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathTotemFormServiceProvider.php
55 lines (48 loc) · 1.65 KB
/
TotemFormServiceProvider.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
46
47
48
49
50
51
52
53
54
55
<?php
namespace Studio\Totem\Providers;
use Illuminate\Support\ServiceProvider;
class TotemFormServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->app['html']->macro('columnSort', function (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 app('html')->toHtmlString(
'<a href="'
.$url
.'">'
.$label
.$icon
.'</a>'
);
});
}
}