Passed
Pull Request — master (#50)
by
unknown
04:43
created

SpecializationController::indexUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\DoctorSpecialization;
7
8
class SpecializationController extends Controller
9
{
10
    /**
11
     * Display a listing of the resource.
12
     *
13
     * @return \Illuminate\Http\Response
14
     */
15
    public function index()
16
    {
17
        $specialization = DoctorSpecialization::orderBy('name', 'desc')->paginate(10);
18
        $data = [
19
            'specialization' => $specialization
20
        ];
21
22
        return view('pages.specialization')->with('data', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('pages.speci...')->with('data', $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
23
    }
24
25
    /**
26
     * Show the form for creating a new resource.
27
     *
28
     * @return \Illuminate\Http\Response
29
     */
30
    public function create()
31
    {
32
        return view('pages.ext.add-specialization');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('pages.ext.add-specialization') returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
33
    }
34
35
    /**
36
     * Store a newly created resource in storage.
37
     *
38
     * @param  \Illuminate\Http\Request  $request
39
     * @return \Illuminate\Http\Response
40
     */
41
    public function store(Request $request)
42
    {
43
        $this->validate($request, [
44
            'degree' => 'required',
45
            'name' => 'required',
46
            'detail' => 'required|min:300'
47
        ]);
48
49
        $specialty = new DoctorSpecialization;
50
        $specialty->degree = $request->input('degree');
51
        $specialty->name = $request->input('name');
52
        $specialty->detail = $request->input('detail');
53
54
        if($specialty->save()) {
55
            return redirect (route('specialty.index'))->with('success', 'Spesialisasi telah di tambahkan');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('s...si telah di tambahkan') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
56
        }
57
58
        return redirect (route('specialty.index'))->with('failed', 'Gagal menambah spesialisasi !');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('s...nambah spesialisasi !') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
59
60
    }
61
62
    /**
63
     * Display the specified resource.
64
     *
65
     * @param  int  $id
66
     * @return \Illuminate\Http\Response
67
     */
68
    public function show($id)
69
    {
70
        $specialization = DoctorSpecialization::find($id);
71
        return view('pages.ext.view-specialization')->with('specialty', $specialization);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('pages.ext.v...alty', $specialization) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
72
    }
73
74
    /**
75
     * Show the form for editing the specified resource.
76
     *
77
     * @param  int  $id
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function edit($id)
81
    {
82
        $specialty = DoctorSpecialization::find($id);
83
        return view('pages.ext.edit-specialization')->with('specialty', $specialty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('pages.ext.e...specialty', $specialty) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
84
    }
85
86
    /**
87
     * Update the specified resource in storage.
88
     *
89
     * @param  \Illuminate\Http\Request  $request
90
     * @param  int  $id
91
     * @return \Illuminate\Http\Response
92
     */
93
    public function update(Request $request, $id)
94
    {
95
        $this->validate($request, [
96
            'degree' => 'required',
97
            'name' => 'required',
98
            'detail' => 'required|min:300'
99
        ]);
100
101
        $specialty = DoctorSpecialization::find($id);
102
        $specialty->degree = $request->input('degree');
103
        $specialty->name = $request->input('name');
104
        $specialty->detail = $request->input('detail');
105
106
        if($specialty->save()) {
107
            return redirect (route('specialty.index'))->with('success', 'Spesialisasi telah di update');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('s...isasi telah di update') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
108
        }
109
110
        return redirect (route('specialty.edit', $id))->with('failed', 'Gagal memperbaharui spesialisasi !');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('s...aharui spesialisasi !') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
111
    }
112
113
    /**
114
     * Remove the specified resource from storage.
115
     *
116
     * @param  int  $id
117
     * @return \Illuminate\Http\Response
118
     */
119
    public function destroy($id)
120
    {
121
        $specialty = DoctorSpecialization::find($id);
122
        if($specialty->delete()) {
123
            return redirect(route('specialty.index'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('specialty.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
124
        }
125
    }
126
127
    public function indexUser()
128
    {
129
        $specialization = DoctorSpecialization::orderBy('name', 'asc')->get();
130
        $data = [
131
            'specialization' => $specialization
132
        ];
133
134
        return view('LSdoctor')->with('data', $data);
135
    }
136
137
    public function indexSearch()
138
    {
139
        $specialization = DoctorSpecialization::orderBy('created_at','desc')->orderBy('name', 'asc')->take(6)->get();
140
        $data = [
141
            'specialization' => $specialization
142
        ];
143
144
        return view('SearchDokter')->with('data', $data);
145
    }
146
}
147