Passed
Push — develop ( c3d6a0...515348 )
by Septianata
14:35
created

ConfigurationController::destroyMultiple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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