1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Console\DataTables\Adminarea; |
6
|
|
|
|
7
|
|
|
use Illuminate\Routing\Route; |
8
|
|
|
use Cortex\Foundation\DataTables\AbstractDataTable; |
9
|
|
|
use Illuminate\Support\Facades\Route as RouteFacade; |
10
|
|
|
|
11
|
|
|
class RoutesDataTable extends AbstractDataTable |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
*/ |
16
|
|
|
protected $createButton = false; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get the query object to be processed by dataTables. |
20
|
|
|
* |
21
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
22
|
|
|
*/ |
23
|
|
|
public function query() |
24
|
|
|
{ |
25
|
|
|
$routes = collect(RouteFacade::getRoutes()); |
26
|
|
|
|
27
|
|
|
$routes->transform(function (Route $route, $key) { |
|
|
|
|
28
|
|
|
return [ |
29
|
|
|
'domain' => (string) $route->getDomain(), |
30
|
|
|
'uri' => (string) $route->uri() === '/' ? '/' : '/'.$route->uri(), |
31
|
|
|
'name' => (string) $route->getName(), |
32
|
|
|
'methods' => (string) implode(', ', $route->methods()), |
33
|
|
|
'action' => (string) $route->getActionName(), |
34
|
|
|
'middleware' => (string) implode(', ', $route->gatherMiddleware()), |
35
|
|
|
]; |
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
return $routes; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Display ajax response. |
43
|
|
|
* |
44
|
|
|
* @return \Illuminate\Http\JsonResponse |
45
|
|
|
*/ |
46
|
|
|
public function ajax() |
47
|
|
|
{ |
48
|
|
|
return datatables($this->query()) |
49
|
|
|
->make(true); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get columns. |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
protected function getColumns(): array |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
'domain' => ['title' => trans('cortex/console::common.domain')], |
61
|
|
|
'uri' => ['title' => trans('cortex/console::common.uri')], |
62
|
|
|
'name' => ['title' => trans('cortex/console::common.name')], |
63
|
|
|
'methods' => ['title' => trans('cortex/console::common.methods')], |
64
|
|
|
'action' => ['title' => trans('cortex/console::common.action')], |
65
|
|
|
'middleware' => ['title' => trans('cortex/console::common.middleware')], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get filename for export. |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
protected function filename(): string |
75
|
|
|
{ |
76
|
|
|
return 'routes-export-'.date('Y-m-d').'-'.time(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.