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

BranchController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Resources\DataTables\BranchResource;
7
use App\Models\Branch;
8
use Illuminate\Http\Request;
9
use Yajra\DataTables\Facades\DataTables;
10
11
class BranchController extends Controller
12
{
13
    /**
14
     * Display a listing of the resource.
15
     *
16
     * @return \Illuminate\Contracts\Support\Renderable
17
     */
18
    public function index()
19
    {
20
        return view('admin.branch.index');
21
    }
22
23
    /**
24
     * Return datatable server side response.
25
     *
26
     * @return \Illuminate\Http\JsonResponse
27
     */
28
    public function datatable()
29
    {
30
        return DataTables::eloquent(Branch::query())
31
            ->setTransformer(fn ($model) => BranchResource::make($model)->resolve())
32
            ->toJson();
33
    }
34
35
    /**
36
     * Show the form for creating a new resource.
37
     *
38
     * @return \Illuminate\Contracts\Support\Renderable
39
     */
40
    public function create()
41
    {
42
        return view('admin.branch.create');
43
    }
44
45
    /**
46
     * Store a newly created resource in storage.
47
     *
48
     * @param  \Illuminate\Http\Request  $request
49
     * @return \Illuminate\Http\RedirectResponse
50
     */
51
    public function store(Request $request)
52
    {
53
        Branch::create($request->all());
54
55
        return redirect()->route('admin.branch.index');
56
    }
57
58
    /**
59
     * Show the form for editing the specified resource.
60
     *
61
     * @param  \App\Models\Branch  $branch
62
     * @return \Illuminate\Contracts\Support\Renderable
63
     */
64
    public function edit(Branch $branch)
65
    {
66
        return view('admin.branch.edit', compact('branch'));
67
    }
68
69
    /**
70
     * Update the specified resource in storage.
71
     *
72
     * @param  \Illuminate\Http\Request  $request
73
     * @param  \App\Models\Branch  $branch
74
     * @return \Illuminate\Http\RedirectResponse
75
     */
76
    public function update(Request $request, Branch $branch)
77
    {
78
        $branch->update($request->all());
79
80
        return redirect()->route('admin.branch.index');
81
    }
82
83
    /**
84
     * Remove the specified resource from storage.
85
     *
86
     * @param  \App\Models\Branch  $branch
87
     * @return \Illuminate\Http\RedirectResponse
88
     */
89
    public function destroy(Branch $branch)
90
    {
91
        $branch->delete();
92
93
        return redirect()->route('admin.branch.index');
94
    }
95
}
96