Cancelled
Push — test-branch ( 5c534a )
by Yonathan
06:17 queued 06:17
created

SkillCrudController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 46
dl 0
loc 100
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 3 1
A setup() 0 67 2
A update() 0 3 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
use Illuminate\Support\Facades\App;
7
use App\Models\Lookup\SkillType;
8
// Validation
9
use App\Http\Requests\SkillCrudRequest as StoreRequest;
10
use App\Http\Requests\SkillCrudRequest as UpdateRequest;
11
12
class SkillCrudController extends CrudController
13
{
14
    /**
15
     * Prepare the admin interface by setting the associated
16
     * model, setting the route, and adding custom columns/fields.
17
     *
18
     * @return void
19
     */
20
    public function setup() : void
21
    {
22
        // Workaround for how the unique_translation validation
23
        // works in App\Http\Requests\SkillCrudRequest
24
        $locale = 'en';
25
        if (null !== $this->request->input('locale')) {
26
            $locale = $this->request->input('locale');
27
        }
28
        App::setLocale($locale);
29
30
        // Eloquent model to associate with this collection
31
        // of views and controller actions.
32
        $this->crud->setModel("App\Models\Skill");
33
        // Custom backpack route.
34
        $this->crud->setRoute("admin/skill");
35
        // Custom strings to display within the backpack UI,
36
        // things like Create Skill, Delete Skills, etc.
37
        $this->crud->setEntityNameStrings('Skill', 'Skills');
38
39
        // Add custom columns to the Skill index view
40
        $this->crud->addColumn([
41
            'name' => 'name',
42
            'type' => 'text',
43
            'label' => 'Name',
44
            'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void {
45
                $query->orWhere('name->' . $locale, 'like', "%$searchTerm%");
46
            },
47
            'orderLogic' => function ($query, $column, $columnDirection) use ($locale) {
48
                return $query->orderBy('name->' . $locale, $columnDirection)->select('*');
49
            }
50
        ]);
51
        $this->crud->addColumn([
52
            'name' => 'description',
53
            'type' => 'text',
54
            'label' => 'Description',
55
            'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void {
56
                $query->orWhere('description->' . $locale, 'like', "%$searchTerm%");
57
            },
58
            'orderable' => false,
59
        ]);
60
        $this->crud->addColumn([
61
            'name' => 'skill_type.name',
62
            'type' => 'text',
63
            'label' => 'Type',
64
            'orderable' => true,
65
            'orderLogic' => function ($query, $column, $columnDirection) use ($locale) {
0 ignored issues
show
Unused Code introduced by
The import $locale is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
66
                return $query->orderBy('skill_type_id', $columnDirection)->select('*');
67
            }
68
        ]);
69
70
        // Add custom fields to the create/update views
71
        $this->crud->addField([
72
            'name' => 'name',
73
            'type' => 'text',
74
            'label' => "Name",
75
        ]);
76
        $this->crud->addField([
77
            'name' => 'description',
78
            'type' => 'textarea',
79
            'label' => "Description"
80
        ]);
81
        $this->crud->addField([
82
            'name' => 'skill_type_id',
83
            'label' => "Type",
84
            'type' => 'select_from_array',
85
            'options' => SkillType::all()->pluck('name', 'id')->toArray(),
86
            'allow_null' => false,
87
        ]);
88
    }
89
90
    /**
91
     * Action for creating a new Skill in the database.
92
     *
93
     * @param SkillCrudRequest $request Incoming form request.
94
     *
95
     * @return \Illuminate\Http\RedirectResponse
96
     */
97
    public function store(StoreRequest $request) // phpcs:ignore
0 ignored issues
show
Unused Code introduced by
The parameter $request 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

97
    public function store(/** @scrutinizer ignore-unused */ StoreRequest $request) // phpcs:ignore

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...
98
    {
99
        return parent::storeCrud();
100
    }
101
102
    /**
103
     * Action for creating a new Skill in the database.
104
     *
105
     * @param SkillCrudRequest $request Incoming form request.
106
     *
107
     * @return \Illuminate\Http\RedirectResponse
108
     */
109
    public function update(UpdateRequest $request) // phpcs:ignore
0 ignored issues
show
Unused Code introduced by
The parameter $request 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

109
    public function update(/** @scrutinizer ignore-unused */ UpdateRequest $request) // phpcs:ignore

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...
110
    {
111
        return parent::updateCrud();
112
    }
113
}
114