diff --git a/app/Doctor.php b/app/Doctor.php index 03097cde..eca5595d 100644 --- a/app/Doctor.php +++ b/app/Doctor.php @@ -78,6 +78,10 @@ public function city() { return $this->belongsTo('App\City', 'city_id'); } + public function thread() { + return $this->hasMany('App\Thread', 'doctor_id'); + } + /** * @param $str * @return string diff --git a/app/Http/Controllers/ThreadAnswerController.php b/app/Http/Controllers/ThreadAnswerController.php index 39c5ea59..97d29b4a 100644 --- a/app/Http/Controllers/ThreadAnswerController.php +++ b/app/Http/Controllers/ThreadAnswerController.php @@ -2,73 +2,107 @@ namespace App\Http\Controllers; +use App\Thread; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; class ThreadAnswerController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function __construct() { - // + $this->middleware('auth:doctor'); } /** - * Show the form for creating a new resource. + * Display a listing of the resource. * * @return \Illuminate\Http\Response */ - public function create() + public function index($id) { - // + $doctor = $this->currentUser(); + if($doctor->id != $id) { + return redirect()->back()->with('warning', 'Anda tidak berhak mengakses laman tersebut.'); + } + + $data = [ + 'doctor' => $doctor, + 'thread' => Thread::where('doctor_id', $doctor->id)->paginate(15) + ]; + return view('pages.profile-thread')->with('data', $data); } /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @param Request $request + * @param $id + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @throws \Illuminate\Validation\ValidationException */ - public function store(Request $request) + public function store(Request $request, $id) { - // - } + $this->validate($request, [ + 'answer' => 'required|min:150' + ]); - /** - * Display the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function show($id) - { - // + $doctor = $this->currentUser(); + $thread = Thread::find($id); + + $thread->doctor_id = $doctor->id; + $thread->answer = $request->input('answer'); + $thread->status = true; + + if($thread->save()) { + return redirect(route('doctor.thread.show', $id))->with('success', 'Jawaban terkirim !'); + } + return redirect()->back()->with('failed', 'Gagal mengirim jawaban.'); } /** * Show the form for editing the specified resource. * - * @param int $id - * @return \Illuminate\Http\Response + * @param $id + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function edit($id) { - // + $thread = Thread::find($id); + if(!$thread) { + abort(404); + } + + $doctor = $this->currentUser(); + $data = [ + 'doctor' => $doctor, + 'thread' => $thread + ]; + + return view('pages.ext.edit-thread')->with('data', $data); } /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request - * @param int $id - * @return \Illuminate\Http\Response + * @param Request $request + * @param $id + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @throws \Illuminate\Validation\ValidationException */ public function update(Request $request, $id) { - // + $this->validate($request, [ + 'answer' => 'required|min:150' + ]); + + $thread = Thread::find($id); + $thread->answer = $request->input('answer'); + $thread->status = true; + + if($thread->save()) { + return redirect(route('doctor.thread.show', $id))->with('success', 'Perubahan jawaban terkirim !'); + } + return redirect()->back()->with('failed', 'Gagal mengirim perubahan jawaban.'); } /** @@ -79,6 +113,25 @@ public function update(Request $request, $id) */ public function destroy($id) { - // + $thread = Thread::find($id); + if($thread->doctor_id != $this->currentUser()->id) { + return redirect()->back()->with('warning', 'Anda tidak berhak menghapus jawaban untuk diskusi tersebut.'); + } + + $thread->doctor_id = null; + $thread->answer = null; + $thread->status = false; + if($thread->save()) { + return redirect()->back()->with('success', 'Jawaban dihapus !'); + } + return redirect()->back()->with('failed', 'Gagal mengahapus jawaban.'); + } + + /** + * @return mixed + */ + private function currentUser() + { + return Auth::guard('doctor')->user(); } } diff --git a/app/Http/Controllers/ThreadAskController.php b/app/Http/Controllers/ThreadAskController.php index 5a4ec6bb..3e24c158 100644 --- a/app/Http/Controllers/ThreadAskController.php +++ b/app/Http/Controllers/ThreadAskController.php @@ -172,8 +172,13 @@ public function destroy($id) return redirect()->back()->with('failed', 'Gagal menghapus ulasan.'); } - - private function currentUser() { + /** + * Get currently logged in user + * + * @return mixed + */ + private function currentUser() + { return Auth::guard('web')->user(); } @@ -181,7 +186,8 @@ private function currentUser() { * @param string $topic * @return ThreadTopic|null */ - private function addTopic(string $topic) { + private function addTopic(string $topic) + { $new = new ThreadTopic; $new->topic_name = $topic; if($new->save()) { @@ -196,7 +202,8 @@ private function addTopic(string $topic) { * @param int $id * @return bool */ - private function deleteTopic($id) { + private function deleteTopic($id) + { $topic = ThreadTopic::find($id); if($topic->delete()) { return true; diff --git a/app/Http/Controllers/ThreadController.php b/app/Http/Controllers/ThreadController.php index a8ffbcbd..ceed5a48 100644 --- a/app/Http/Controllers/ThreadController.php +++ b/app/Http/Controllers/ThreadController.php @@ -2,42 +2,55 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App\Thread; +use App\ThreadTopic; +use Illuminate\Support\Facades\Auth; class ThreadController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function __construct() { -// abort(503); - return view('pages.thread'); + $this->middleware('auth:admin', ['except' => [ + 'index', 'show' + ]]); } /** - * Show the form for creating a new resource. + * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @param $query + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function create() + public function index($query) { - // - } + $threads = null; + $count = null; + if($query == "all") { + $threads = Thread::orderBy('created_at', 'desc')->paginate(15); + } elseif($query == "answered") { + $threads = Thread::where('status', true) + ->orderBy('created_at', 'desc') + ->paginate(15); + } else { + $threads = Thread::where('status', false) + ->orderBy('created_at', 'desc') + ->paginate(15); + } - /** - * Store a newly created resource in storage. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - // + $data = [ + 'threads' => $threads, + 'query' => $query, + 'count' => [ + 'all' => count(Thread::all()), + 'answered' => count(Thread::where('status', true)->get()), + 'unanswered' => count(Thread::where('status', false)->get()) + ] + ]; + + return view('pages.thread')->with('data', $data); } + /** * Display the specified resource. * @@ -46,40 +59,48 @@ public function store(Request $request) */ public function show($id) { - // - } + $thread = Thread::find($id); + if(!$thread) { + abort(404); + } - /** - * Show the form for editing the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function edit($id) - { - // + $doctor = Auth::guard('doctor')->user(); + $data = [ + 'thread' => $thread, + 'doctor' => $doctor + ]; + return view('pages.ext.view-thread')->with('data', $data); } + /** - * Update the specified resource in storage. + * Remove the specified resource from storage. * - * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ - public function update(Request $request, $id) + public function destroy($id) { - // + $thread = Thread::find($id); + if($thread->delete() && $this->deleteTopic($thread->id_topic)) { + return redirect(route('admin.thread.index', ['query' => "all"]))->with('success', 'Diskusi dihapus !'); + } + return redirect()->back()->with('failed', 'Gagal menghapus diskusi.'); } + /** - * Remove the specified resource from storage. + * Delete topic with given id * - * @param int $id - * @return \Illuminate\Http\Response + * @param $id + * @return bool */ - public function destroy($id) + public function deleteTopic($id) { - // + $topic = ThreadTopic::find($id); + if($topic->delete()) { + return true; + } + return false; } } diff --git a/readme.md b/readme.md index c9651801..4d939e08 100644 --- a/readme.md +++ b/readme.md @@ -145,5 +145,5 @@ Great, now you can try and login as admin by going to `localhost:8000/admin/logi SIFIKS is open-source project licensed under the [MIT license](https://opensource.org/licenses/MIT). -## Domain +## Live Action Please visit : https://sifiks.kodeskillet.com/. diff --git a/resources/views/ask-form.blade.php b/resources/views/ask-form.blade.php index a71e2111..dfc1e78a 100644 --- a/resources/views/ask-form.blade.php +++ b/resources/views/ask-form.blade.php @@ -50,7 +50,7 @@ - diff --git a/resources/views/ask-view.blade.php b/resources/views/ask-view.blade.php index 9e15399f..909925ed 100644 --- a/resources/views/ask-view.blade.php +++ b/resources/views/ask-view.blade.php @@ -81,7 +81,7 @@ @include('layouts.inc.recent-thread')
- doctor + doctor
diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index ab635d2c..722870d6 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -16,8 +16,8 @@ @if ($errors->has('email')) - {{ $errors->first('email') }} - + {{ $errors->first('email') }} + @endif @@ -28,22 +28,11 @@ @if ($errors->has('password')) - {{ $errors->first('password') }} - + {{ $errors->first('password') }} + @endif -{{--
--}} -{{--
--}} -{{--
--}} -{{-- --}} -{{--  --}} -{{-- --}} -{{--
--}} -{{--
--}} -{{--
--}}
diff --git a/resources/views/layouts/adm-app.blade.php b/resources/views/layouts/adm-app.blade.php index 6ca9d5b3..52c6d7e2 100644 --- a/resources/views/layouts/adm-app.blade.php +++ b/resources/views/layouts/adm-app.blade.php @@ -80,7 +80,7 @@ @else skin-red @endif - hold-transition sidebar-mini fixed + hold-transition sidebar-mini "> @@ -236,14 +236,14 @@
  • @if(session('role') == "Admin" && Auth::guard('admin')->check()) - + - Forum + Diskusi @elseif(session('role') == "Doctor" && Auth::guard('doctor')->check()) - + - Forum + Diskusi @endif
  • diff --git a/resources/views/layouts/admin-profile.blade.php b/resources/views/layouts/admin-profile.blade.php index 8f970221..8c9d2d22 100644 --- a/resources/views/layouts/admin-profile.blade.php +++ b/resources/views/layouts/admin-profile.blade.php @@ -75,17 +75,17 @@ @endif > Artikel anda - + {{ count($data[session('guard')]->article) }} @auth('doctor')
  • - - Thread terjawab - - 0 + + Diskusi terjawab + + {{ count($data['doctor']->thread) }}
  • @@ -93,7 +93,7 @@ Rumah Sakit anda - + diff --git a/resources/views/layouts/inc/messages.blade.php b/resources/views/layouts/inc/messages.blade.php index 9e148a29..086d4508 100644 --- a/resources/views/layouts/inc/messages.blade.php +++ b/resources/views/layouts/inc/messages.blade.php @@ -10,7 +10,7 @@ @endif @if(session('failed')) -
    -
    - @endsection diff --git a/resources/views/pages/ext/view-specialization.blade.php b/resources/views/pages/ext/view-specialization.blade.php index 356d741f..777e5839 100644 --- a/resources/views/pages/ext/view-specialization.blade.php +++ b/resources/views/pages/ext/view-specialization.blade.php @@ -9,7 +9,7 @@ ( {{ $specialty->degree }} )