Passed
Push — develop ( 6302a9...3db2fb )
by Septianata
04:45
created

ConfigurationController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 27
dl 0
loc 114
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 8 1
A create() 0 3 1
A destroy() 0 8 1
A store() 0 8 1
A destroyMultiple() 0 8 1
A edit() 0 3 1
A index() 0 3 1
A datatable() 0 5 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 Yajra\DataTables\Facades\DataTables;
12
13
class ConfigurationController extends Controller
14
{
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return \Illuminate\Contracts\Support\Renderable
19
     */
20 1
    public function index()
21
    {
22 1
        return view('admin.configuration.index');
23
    }
24
25
    /**
26
     * Return datatable server side response.
27
     *
28
     * @return \Illuminate\Http\JsonResponse
29
     */
30 1
    public function datatable()
31
    {
32 1
        return DataTables::eloquent(Configuration::query())
33 1
            ->setTransformer(fn ($model) => ConfigurationResource::make($model)->resolve())
34 1
            ->toJson();
35
    }
36
37
    /**
38
     * Show the form for creating a new resource.
39
     *
40
     * @return \Illuminate\Contracts\Support\Renderable
41
     */
42 1
    public function create()
43
    {
44 1
        return view('admin.configuration.create');
45
    }
46
47
    /**
48
     * Store a newly created resource in storage.
49
     *
50
     * @param  \App\Http\Requests\Configuration\StoreRequest  $request
51
     * @return \Illuminate\Http\RedirectResponse
52
     */
53 1
    public function store(StoreRequest $request)
54
    {
55 1
        Configuration::create($request->all());
56
57 1
        return redirect()->route('admin.configuration.index')->with([
58
            'alert' => [
59 1
                'type' => 'alert-success',
60 1
                'message' => trans('The :resource was created!', ['resource' => trans('admin-lang.configuration')]),
61
            ],
62
        ]);
63
    }
64
65
    /**
66
     * Show the form for editing the specified resource.
67
     *
68
     * @param  \App\Models\Configuration  $configuration
69
     * @return \Illuminate\Contracts\Support\Renderable
70
     */
71 1
    public function edit(Configuration $configuration)
72
    {
73 1
        return view('admin.configuration.edit', compact('configuration'));
74
    }
75
76
    /**
77
     * Update the specified resource in storage.
78
     *
79
     * @param  \App\Http\Requests\Configuration\UpdateRequest  $request
80
     * @param  \App\Models\Configuration  $configuration
81
     * @return \Illuminate\Http\RedirectResponse
82
     */
83 1
    public function update(UpdateRequest $request, Configuration $configuration)
84
    {
85 1
        $configuration->update($request->all());
86
87 1
        return redirect()->route('admin.configuration.index')->with([
88
            'alert' => [
89 1
                'type' => 'alert-success',
90 1
                'message' => trans('The :resource was updated!', ['resource' => trans('admin-lang.configuration')]),
91
            ],
92
        ]);
93
    }
94
95
    /**
96
     * Remove the specified resource from storage.
97
     *
98
     * @param  \App\Models\Configuration  $configuration
99
     * @return \Illuminate\Http\RedirectResponse
100
     */
101 1
    public function destroy(Configuration $configuration)
102
    {
103 1
        $configuration->delete();
104
105 1
        return redirect()->route('admin.configuration.index')->with([
106
            'alert' => [
107 1
                'type' => 'alert-success',
108 1
                'message' => trans('The :resource was deleted!', ['resource' => trans('admin-lang.configuration')]),
109
            ],
110
        ]);
111
    }
112
113
    /**
114
     * Remove the specified list of resource from storage.
115
     *
116
     * @param  \Illuminate\Http\Request  $request
117
     * @return \Illuminate\Http\RedirectResponse
118
     */
119 1
    public function destroyMultiple(Request $request)
120
    {
121 1
        Configuration::destroy($request->input('checkbox', []));
122
123 1
        return redirect()->route('admin.configuration.index')->with([
124
            'alert' => [
125 1
                'type' => 'alert-success',
126 1
                'message' => trans('The :resource was deleted!', ['resource' => trans('admin-lang.configuration')]),
127
            ],
128
        ]);
129
    }
130
}
131