Passed
Pull Request — master (#58)
by
unknown
04:13
created

SpecializationController::destroy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\City;
7
use App\DoctorSpecialization;
8
9
class SpecializationController extends Controller
10
{
11
    /**
12
     * Display a listing of the resource.
13
     *
14
     * @return \Illuminate\Http\Response
15
     */
16
    public function index()
17
    {
18
        $specialization = DoctorSpecialization::orderBy('name', 'desc')->paginate(10);
19
        $data = [
20
            'specialization' => $specialization
21
        ];
22
23
        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...
24
    }
25
26
    /**
27
     * Show the form for creating a new resource.
28
     *
29
     * @return \Illuminate\Http\Response
30
     */
31
    public function create()
32
    {
33
        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...
34
    }
35
36
    /**
37
     * Store a newly created resource in storage.
38
     *
39
     * @param  \Illuminate\Http\Request  $request
40
     * @return \Illuminate\Http\Response
41
     */
42
    public function store(Request $request)
43
    {
44
        $this->validate($request, [
45
            'degree' => 'required',
46
            'name' => 'required',
47
            'detail' => 'required|min:300'
48
        ]);
49
50
        $specialty = new DoctorSpecialization;
51
        $specialty->degree = $request->input('degree');
52
        $specialty->name = $request->input('name');
53
        $specialty->detail = $request->input('detail');
54
55
        if($specialty->save()) {
56
            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...
57
        }
58
59
        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...
60
61
    }
62
63
    /**
64
     * Display the specified resource.
65
     *
66
     * @param  int  $id
67
     * @return \Illuminate\Http\Response
68
     */
69
    public function show($id)
70
    {
71
        $specialization = DoctorSpecialization::find($id);
72
        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...
73
    }
74
75
    /**
76
     * Show the form for editing the specified resource.
77
     *
78
     * @param  int  $id
79
     * @return \Illuminate\Http\Response
80
     */
81
    public function edit($id)
82
    {
83
        $specialty = DoctorSpecialization::find($id);
84
        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...
85
    }
86
87
    /**
88
     * Update the specified resource in storage.
89
     *
90
     * @param  \Illuminate\Http\Request  $request
91
     * @param  int  $id
92
     * @return \Illuminate\Http\Response
93
     */
94
    public function update(Request $request, $id)
95
    {
96
        $this->validate($request, [
97
            'degree' => 'required',
98
            'name' => 'required',
99
            'detail' => 'required|min:300'
100
        ]);
101
102
        $specialty = DoctorSpecialization::find($id);
103
        $specialty->degree = $request->input('degree');
104
        $specialty->name = $request->input('name');
105
        $specialty->detail = $request->input('detail');
106
107
        if($specialty->save()) {
108
            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...
109
        }
110
111
        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...
112
    }
113
114
    /**
115
     * Remove the specified resource from storage.
116
     *
117
     * @param  int  $id
118
     * @return \Illuminate\Http\Response
119
     */
120
    public function destroy($id)
121
    {
122
        $specialty = DoctorSpecialization::find($id);
123
        if($specialty->delete()) {
124
            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...
125
        }
126
    }
127
128
    public function indexUser()
129
    {
130
        $specialization = DoctorSpecialization::orderBy('name', 'asc')->get();
131
        $data = [
132
            'specialization' => $specialization
133
        ];
134
135
        return view('LSdoctor')->with('data', $data);
136
    }
137
138
    public function indexSearch()
139
    {
140
        $specialization = DoctorSpecialization::orderBy('created_at','desc')->orderBy('name', 'asc')->take(6)->get();
141
        $location = City::pluck('name','id');
142
        $data = [
143
            'specialization' => $specialization,
144
            'location' => $location
145
        ];
146
147
        return view('SearchDokter')->with('data', $data);
148
    }
149
150
    public function searchSpecialty(Request $request)
151
    {
152
        $specialization = DoctorSpecialization::where('name','LIKE','%'.$request->specialty.'%')->orderBy('name','asc')->get();
153
        $data = [
154
            'specialization' => $specialization
155
        ];
156
157
        return view('LSdoctor')->with('data',$data);
158
    }
159
}
160