Passed
Push — develop ( 6dcea6...5ae9a6 )
by Septianata
16:24
created

ConfigurationController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Resources\DataTables\ConfigurationResource;
7
use App\Models\Configuration;
8
use App\Http\Requests\Configuration\StoreRequest;
9
use App\Http\Requests\Configuration\UpdateRequest;
10
use Illuminate\Http\Request;
11
use Illuminate\Support\Facades\DB;
12
use Yajra\DataTables\Facades\DataTables;
13
14
class ConfigurationController extends Controller
15
{
16
    /**
17
     * Create a new instance class.
18
     *
19
     * @return void
20
     */
21 8
    public function __construct()
22
    {
23 8
        $this->authorizeResource(Configuration::class, 'configuration');
24 8
    }
25
26
    /**
27
     * Display a listing of the resource.
28
     *
29
     * @return \Illuminate\Contracts\Support\Renderable
30
     */
31 1
    public function index()
32
    {
33 1
        return view('admin.configuration.index');
34
    }
35
36
    /**
37
     * Return datatable server side response.
38
     *
39
     * @return \Illuminate\Http\JsonResponse
40
     */
41 1
    public function datatable()
42
    {
43 1
        $this->authorize('viewAny', Configuration::class);
44
45 1
        return DataTables::eloquent(Configuration::query())
46 1
            ->setTransformer(fn ($model) => ConfigurationResource::make($model)->resolve())
47 1
            ->toJson();
48
    }
49
50
    /**
51
     * Show the form for creating a new resource.
52
     *
53
     * @return \Illuminate\Contracts\Support\Renderable
54
     */
55 1
    public function create()
56
    {
57 1
        return view('admin.configuration.create');
58
    }
59
60
    /**
61
     * Store a newly created resource in storage.
62
     *
63
     * @param  \App\Http\Requests\Configuration\StoreRequest  $request
64
     * @return \Illuminate\Http\RedirectResponse
65
     */
66 1
    public function store(StoreRequest $request)
67
    {
68 1
        Configuration::create($request->validated());
69
70 1
        return redirect()->route('admin.configuration.index')->with([
71
            'alert' => [
72 1
                'type' => 'alert-success',
73 1
                'message' => trans('The :resource was created!', ['resource' => trans('admin-lang.configuration')]),
74
            ],
75
        ]);
76
    }
77
78
    /**
79
     * Show the form for editing the specified resource.
80
     *
81
     * @param  \App\Models\Configuration  $configuration
82
     * @return \Illuminate\Contracts\Support\Renderable
83
     */
84 1
    public function edit(Configuration $configuration)
85
    {
86 1
        return view('admin.configuration.edit', compact('configuration'));
87
    }
88
89
    /**
90
     * Update the specified resource in storage.
91
     *
92
     * @param  \App\Http\Requests\Configuration\UpdateRequest  $request
93
     * @param  \App\Models\Configuration  $configuration
94
     * @return \Illuminate\Http\RedirectResponse
95
     */
96 1
    public function update(UpdateRequest $request, Configuration $configuration)
97
    {
98 1
        $configuration->update($request->validated());
99
100 1
        return redirect()->route('admin.configuration.edit', $configuration)->with([
101
            'alert' => [
102 1
                'type' => 'alert-success',
103 1
                'message' => trans('The :resource was updated!', ['resource' => trans('admin-lang.configuration')]),
104
            ],
105
        ]);
106
    }
107
108
    /**
109
     * Remove the specified resource from storage.
110
     *
111
     * @param  \App\Models\Configuration  $configuration
112
     * @return \Illuminate\Http\RedirectResponse
113
     */
114 1
    public function destroy(Configuration $configuration)
115
    {
116 1
        $configuration->delete();
117
118 1
        return redirect()->route('admin.configuration.index')->with([
119
            'alert' => [
120 1
                'type' => 'alert-success',
121 1
                'message' => trans('The :resource was deleted!', ['resource' => trans('admin-lang.configuration')]),
122
            ],
123
        ]);
124
    }
125
126
    /**
127
     * Remove the specified list of resource from storage.
128
     *
129
     * @param  \Illuminate\Http\Request  $request
130
     * @return \Illuminate\Http\RedirectResponse
131
     */
132 1
    public function destroyMultiple(Request $request)
133
    {
134 1
        DB::transaction(function () use ($request) {
135 1
            foreach ($request->input('checkbox', []) as $id) {
136 1
                $configuration = Configuration::find($id, 'id');
137
138 1
                $this->authorize('delete', $configuration);
139
140 1
                $configuration->delete();
141
            }
142 1
        });
143
144 1
        return redirect()->route('admin.configuration.index')->with([
145
            'alert' => [
146 1
                'type' => 'alert-success',
147 1
                'message' => trans('The :resource was deleted!', ['resource' => trans('admin-lang.configuration')]),
148
            ],
149
        ]);
150
    }
151
}
152