Completed
Push — device-groups ( cccab4...a9d029 )
by Tony
03:45
created

DeviceGroupDataTable::filename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace App\DataTables;
4
5
6
use App\Models\DeviceGroup;
7
8
class DeviceGroupDataTable extends BaseDataTable
9
{
10
    /**
11
     * Display ajax response.
12
     *
13
     * @return \Illuminate\Http\JsonResponse
14
     */
15
    public function ajax()
16
    {
17
        return $this->datatables
18
            ->eloquent($this->query())
19 View Code Duplication
            ->addColumn('actions', function($group) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
                $edit = '<button type="button" class="btn btn-xs btn-primary showModal"  data-toggle="modal" data-target="#generalModal" data-href="'.
21
                    route('device-groups.edit', ['group_id' => $group->id]).
22
                    '"><i class="fa fa-edit fa-lg fa-fw"></i><span class="hidden-xs"> '.trans('button.edit').'</span></button> ';
23
24
                $delete = '<button type="button" class="btn btn-xs btn-danger" data-toggle="modal" data-target="#deleteModal" data-href="'.
25
                    route('device-groups.destroy', ['group_id' => $group->id]).
26
                    '"><i class="fa fa-trash fa-lg fa-fw"></i><span class="hidden-xs"> '.trans('button.delete').'</span></button> ';
27
28
                return $edit.$delete;
29
            })
30
            ->make(true);
31
    }
32
33
    /**
34
     * Get the query object to be processed by datatables.
35
     *
36
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
37
     */
38
    public function query()
39
    {
40
        $devicegroups = DeviceGroup::query();
41
        return $this->applyScopes($devicegroups);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->applyScopes($devicegroups); of type Illuminate\Database\Quer...tabase\Eloquent\Builder adds the type Illuminate\Database\Query\Builder to the return on line 41 which is incompatible with the return type declared by the interface Yajra\Datatables\Contrac...ataTableContract::query of type Illuminate\Database\Eloquent\Builder.
Loading history...
42
    }
43
44
    /**
45
     * Get columns.
46
     *
47
     * @return array
48
     */
49
    public function getColumns()
50
    {
51
        return [
52
            'id' => [
53
                'visible' => false,
54
            ],
55
            'name' => [
56
                'title' => trans('devices.groups.name'),
57
            ],
58
            'desc' => [
59
                'title' => trans('devices.groups.desc'),
60
            ],
61
            'pattern' => [
62
                'title' => trans('devices.groups.pattern'),
63
            ],
64
            'actions' => [
65
                'title' => trans('devices.groups.actions'),
66
            ]
67
        ];
68
    }
69
70
    /**
71
     * Get filename for export.
72
     *
73
     * @return string
74
     */
75
    protected function filename()
76
    {
77
        return 'devicegroups';
78
    }
79
}