Completed
Push — main ( 3e1c9f...1d9eb2 )
by PRATIK
19s queued 16s
created

SliderTable::columns()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 25
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 20
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 25
rs 9.6
1
<?php
2
3
namespace Adminetic\Website\Http\Livewire\Admin\Slider;
4
5
use Adminetic\Website\Models\Admin\Slider;
0 ignored issues
show
Bug introduced by
The type Adminetic\Website\Models\Admin\Slider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Support\Facades\Blade;
8
use Rappasoft\LaravelLivewireTables\DataTableComponent;
9
use Rappasoft\LaravelLivewireTables\Views\Column;
10
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
11
12
class SliderTable extends DataTableComponent
13
{
14
    public function builder(): Builder
15
    {
16
        return Slider::query()
17
            ->orderBy('position'); // Eager load anything; // Select some things
18
    }
19
20
    public array $bulkActions = [
21
        'bulkDelete' => 'Bulk Delete',
22
    ];
23
24
    public function bulkDelete()
25
    {
26
        Slider::whereIn('id', $this->getSelected())->delete();
27
    }
28
29
    public function filters(): array
30
    {
31
        return [
32
            SelectFilter::make('Active')
33
                ->options([
34
                    '' => 'All',
35
                    '1' => 'Active',
36
                    '0' => 'Inactive',
37
                ])
38
                ->filter(function (Builder $builder, string $value) {
39
                    if ($value === '1') {
40
                        $builder->where('active', true);
41
                    } elseif ($value === '0') {
42
                        $builder->where('active', false);
43
                    }
44
                }),
45
        ];
46
    }
47
48
    public function configure(): void
49
    {
50
        $this->setPrimaryKey('id');
51
52
        $this->setEagerLoadAllRelationsEnabled();
53
54
        $this->setEmptyMessage('No Slider found');
55
56
        $this->setReorderStatus(true);
57
58
        $this->setDefaultReorderSort('position', 'asc');
59
    }
60
61
    public function reorder($items): void
62
    {
63
        foreach ($items as $item) {
64
            Slider::find((int) $item['value'])->update(['position' => (int) $item['order']]);
65
        }
66
    }
67
68
    public function columns(): array
69
    {
70
        return [
71
            Column::make('ID', 'id')
72
                ->sortable()
73
                ->searchable(),
74
            Column::make('Title', 'title')
75
                ->sortable()
76
                ->searchable(),
77
            Column::make('Text', 'text')
78
                ->searchable()
79
                ->collapseOnTablet(),
80
            Column::make('Active', 'active')
81
                ->format(
82
                    fn ($value, $row, Column $column) => '<span class="badge badge-'.($row->getRawOriginal('active') ? 'success' : 'danger').' ">'.($row->getRawOriginal('active') ? 'Active' : 'Inactive').'</span>'
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

82
                    fn ($value, $row, /** @scrutinizer ignore-unused */ Column $column) => '<span class="badge badge-'.($row->getRawOriginal('active') ? 'success' : 'danger').' ">'.($row->getRawOriginal('active') ? 'Active' : 'Inactive').'</span>'

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
                )
84
                ->html()
85
                ->collapseOnTablet(),
86
87
            Column::make('Action')
88
                ->label(
89
                    fn ($row, Column $column) => Blade::render('<x-adminetic-action :model="$model" route="slider" />', ['model' => $row])
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

89
                    fn ($row, /** @scrutinizer ignore-unused */ Column $column) => Blade::render('<x-adminetic-action :model="$model" route="slider" />', ['model' => $row])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
                )
91
                ->html()
92
                ->collapseOnTablet(),
93
        ];
94
    }
95
}
96