FaqTable::columns()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 17
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 22
rs 9.7
1
<?php
2
3
namespace Adminetic\Website\Http\Livewire\Admin\Faq;
4
5
use Adminetic\Website\Models\Admin\Faq;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Support\Facades\Blade;
8
use Rappasoft\LaravelLivewireTables\DataTableComponent;
9
use Rappasoft\LaravelLivewireTables\Views\Column;
10
11
class FaqTable extends DataTableComponent
12
{
13
    public function builder(): Builder
14
    {
15
        return Faq::query()
0 ignored issues
show
Bug Best Practice introduced by
The expression return Adminetic\Website...()->orderBy('position') could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
16
            ->orderBy('position'); // Eager load anything; // Select some things
17
    }
18
19
    public array $bulkActions = [
20
        'bulkDelete' => 'Bulk Delete',
21
    ];
22
23
    public function bulkDelete()
24
    {
25
        Faq::whereIn('id', $this->getSelected())->delete();
26
    }
27
28
    public function configure(): void
29
    {
30
        $this->setPrimaryKey('id');
31
32
        $this->setEagerLoadAllRelationsEnabled();
33
34
        $this->setEmptyMessage('No faq found');
35
36
        $this->setReorderStatus(true);
37
38
        $this->setDefaultReorderSort('position', 'asc');
39
    }
40
41
    public function reorder($items): void
42
    {
43
        foreach ($items as $item) {
44
            Faq::find((int) $item['value'])->update(['position' => (int) $item['order']]);
45
        }
46
    }
47
48
    public function columns(): array
49
    {
50
        return [
51
            Column::make('ID', 'id')
52
                ->sortable()
53
                ->searchable(),
54
            Column::make('Question', 'question')
55
                ->format(
56
                    fn ($value, $row, Column $column) => $row->question
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

56
                    fn ($value, $row, /** @scrutinizer ignore-unused */ Column $column) => $row->question

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...
57
                )
58
                ->html(),
59
            Column::make('Answer', 'answer')
60
                ->format(
61
                    fn ($value, $row, Column $column) => $row->question
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

61
                    fn ($value, $row, /** @scrutinizer ignore-unused */ Column $column) => $row->question

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...
62
                )
63
                ->html()->collapseOnTablet(),
64
            Column::make('Action')
65
                ->label(
66
                    fn ($row, Column $column) => Blade::render('<x-adminetic-action :model="$model" route="faq" />', ['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

66
                    fn ($row, /** @scrutinizer ignore-unused */ Column $column) => Blade::render('<x-adminetic-action :model="$model" route="faq" />', ['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...
67
                )
68
                ->html()
69
                ->collapseOnTablet(),
70
        ];
71
    }
72
}
73