Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
filter doctors by speciality or search
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhsianturi committed Feb 23, 2018
1 parent a9fb8e2 commit 4221623
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 69 deletions.
8 changes: 3 additions & 5 deletions app/Filters/DoctorFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

class DoctorFilters extends Filters
{
protected $filters = ['polyclinic'];
protected $filters = ['name'];

protected function polyclinic($polyclinic)
protected function name($full_name)
{
return $this->builder->whereHas('polyclinic', function ($query) use ($polyclinic) {
$query->where('name', $polyclinic);
});
return $this->builder->where('full_name', 'LIKE', "%$full_name%");
}
}
28 changes: 27 additions & 1 deletion app/Http/Controllers/Doctors/DoctorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Doctors;

use App\Models\Doctor\Doctor;
use App\Filters\DoctorFilters;
use App\Http\Controllers\Controller;
use App\Http\Requests\DoctorRequest;
use Illuminate\Support\Facades\Auth;
Expand All @@ -12,7 +13,21 @@ class DoctorController extends Controller
{
public function __construct()
{
$this->middleware(['role:doctor']);
$this->middleware(['role:doctor'])->except(['index', 'show']);
}

public function index(Speciality $speciality, DoctorFilters $filters)
{
$doctors = $this->getDoctors($speciality, $filters);

$specialities = Speciality::all();

return view('doctors.index', compact('doctors', 'specialities'));
}

public function show(Speciality $speciality, Doctor $doctor)
{
return view('doctors.show', compact('doctor'));
}

public function edit()
Expand All @@ -38,4 +53,15 @@ public function update(DoctorRequest $request, Doctor $doctor)

return redirect()->back();
}

protected function getDoctors(Speciality $speciality, DoctorFilters $filters)
{
$doctors = Doctor::with('speciality', 'group')->latest()->filter($filters);

if ($speciality->exists) {
$doctors->where('speciality_id', $speciality->id);
}

return $doctors->paginate(12);
}
}
2 changes: 1 addition & 1 deletion app/Http/Requests/DoctorRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function authorize()
public function rules()
{
return [
'speciality_id' => 'required',
'speciality_id' => 'required|exists:specialities,id',
'full_name' => 'required|string|max:255',
'years_of_experience' => 'required|numeric',
'qualification' => 'required|string|max:25',
Expand Down
42 changes: 42 additions & 0 deletions resources/views/doctors/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@extends('layouts.master')

@section('title', 'All doctors')

@section('content')
<div class="page-header border-bottom box-shadow-nav">
<div class="container text-secondary">
<a href="/doctors" class="badge badge-info">All</a>
@foreach ($specialities as $speciality)
<a href="/doctors/{{$speciality->slug}}" class="badge badge-info">{{ $speciality->name }}</a>
@endforeach
</div>
</div>

<main class="container">
<div class="row my-3 p-3">

@forelse ($doctors as $doctor)
<div class="col-md-4">
<div class="media">
<img src="{{ asset('img/example-avatar.png') }}" alt="avatar" class="img-responsive mr-2" width="50" height="50">
<p class="media-body pb-3 mb-3">
<a href="/doctors/{{$doctor->speciality->slug}}/{{$doctor->slug}}" class="d-block font-weight-bold">
{{ $doctor->full_name }}
</a>
<a href="/{{$doctor->group->slug}}" class="text-secondary font-weight-light">
{{ $doctor->group->name }}
</a>
</p>
</div>
</div>
@empty
<div class="col-md-12">
<h4 class="text-center">There are no relevant results at this time</h4>
</div>
@endforelse

{{ $doctors->links('vendor.pagination.bootstrap-4') }}

</div>
</main>
@endsection
55 changes: 0 additions & 55 deletions resources/views/explore.blade.php

This file was deleted.

7 changes: 2 additions & 5 deletions resources/views/partials/master/navbar.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<div class="navbar-collapse offcanvas-collapse" id="navbarMenu">

<form action="{{ route('search') }}" method="get" class="form-inline mr-auto">
<form action="/doctors" method="get" class="form-inline mr-auto">
<div class="input-group">
<input class="search-input" type="search" name="q" placeholder="find a doctor...">
<input class="search-input" type="search" name="name" placeholder="find a doctor...">
</div>
</form>

<ul class="navbar-nav my-2 my-lg-0">
<li class="nav-item">
<a href="/explore" class="nav-link @yield('explore')">Explore</a>
</li>
@guest
<li class="nav-item">
<a href="/login" class="nav-link">My Account</a>
Expand Down
9 changes: 7 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

// home
Route::get('/', 'HomeController@home');
Route::get('/search', 'HomeController@search')->name('search');
Route::get('/explore', 'HomeController@explore');

// doctor's profile
Route::get('/doctors', 'Doctors\DoctorController@index');
Route::get('/doctors/{speciality}', 'Doctors\DoctorController@index');
Route::get('/doctors/{speciality}/{doctor}', 'Doctors\DoctorController@show');

// schedule an appointment
Route::get('/scheduling/physical-appointment', 'Schedulings\PhysicalAppointmentController@index');

// Authentication default
Expand Down

0 comments on commit 4221623

Please sign in to comment.