Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated departments pge #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions .env.example

This file was deleted.

15 changes: 11 additions & 4 deletions app/Http/Livewire/Admins/Departments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use App\Models\department;
use App\Models\hod;
use App\Models\block;
use App\Models\doctor;
use Livewire\Component;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\ImageManagerStatic;
Expand Down Expand Up @@ -126,11 +127,17 @@ public function delete($id)

public function render()
{

$block_id=[];
$departments=department::all();
foreach($departments as $deptItem){
$block_id[] = $deptItem->block_id;
}
$doc_name=doctor::with(['employ'])->get();

return view('livewire.admins.departments',[
'departments' => department::latest()->paginate(10),
'hods' => hod::all(),
'blocks' => block::all(),
'departments' => department::with(['hod'])->paginate(10),
'hods' => $doc_name,
'blocks' => block::whereIn('id',$block_id)->get(),
])->layout('admins.layouts.app');
}
}
170 changes: 170 additions & 0 deletions app/Http/Livewire/Admins/Docter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php

namespace App\Http\Livewire\Admins;

use App\Models\department;
use App\Models\doctor;
use Livewire\Component;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\ImageManagerStatic;
use Illuminate\Support\Str;
use Livewire\WithPagination;

use Livewire\WithFileUploads;

class Docter extends Component
{
use WithFileUploads;
use WithPagination;

protected $paginationTheme = 'bootstrap';


public $name;
public $Email;
public $Password;
public $Address;
public $Phone;
public $department = 'null';
public $Specialization;
public $Photo;

public $edit_photo;
public $edit_doctor_id;
public $button_text = "Add New doctor";



public function add_doctor()
{
if ($this->edit_photo) {

$this->update($this->edit_doctor_id);

}else{
$this->validate([
'name' => 'required||min:6|max:50',
'Email' => 'required|email|unique:doctors,email,except,id',
'Password' => 'required|min:6',
'Address' => 'required',
'Phone' => 'required|unique:doctors,phone,except,id',
'department' => 'required',
'Specialization' => 'required',
'Photo' => 'required|image|max:3072', //3MB
]);
doctor::create([
'name' => $this->name,
'email' => $this->Email,
'password' => bcrypt($this->Password),
'address' => $this->Address,
'phone' => $this->Phone,
'department' => $this->department,
'specialization' => $this->Specialization,
'photo_path' => $this->storeImage(),
]);
//unset variables
$this->name="";
$this->Email="";
$this->Password="";
$this->Address="";
$this->Phone="";
$this->department="";
$this->Specialization="";
$this->address="";
$this->Photo="";
session()->flash('message', 'Doctor Created successfully.');
}

}

public function storeImage()
{
if (!$this->Photo) {
return null;
}
$imag = ImageManagerStatic::make($this->Photo)->encode('jpg');
$name = Str::random() . '.jpg';
Storage::disk('public')->put($name, $imag);
return env('APP_URL').'storage/'. $name;
}

public function edit($id)
{
$doctor = doctor::findOrFail($id);
$this->edit_doctor_id = $id;

$this->name = $doctor->name;
$this->Email = $doctor->email;
$this->Address = $doctor->address;
$this->Phone = $doctor->phone;
$this->department = $doctor->department;
//$this->Specialization = $doctor->specialization;
$this->edit_photo = $doctor->photo_path;

$this->button_text="Update Doctor";
}
public function update($id)
{
$this->validate([
'name' => 'required||min:6|max:50',
'Email' => 'required|email',
'Password' => 'required|min:6',
'Address' => 'required',
'Phone' => 'required',
'department' => 'required',
'Specialization' => 'required',
]);

$doctor = doctor::findOrFail($id);
$doctor->name = $this->name;
$doctor->email = $this->Email;
$doctor->password = bcrypt($this->Password);
$doctor->address = $this->Address;
$doctor->phone = $this->Phone;
$doctor->department = $this->department;
//$doctor->specialization = $this->Specialization;

if ($this->Photo) {
$this->validate([
'Photo' => 'required|image|max:3072',
]);
Storage::disk('public')->delete($doctor->photo_path);
$doctor->photo_path = $this->storeImage();

}

$doctor->save();

$this->name="";
$this->Email="";
$this->Password="";
$this->Password="";
$this->Address="";
$this->Phone="";
$this->department="";
//$this->Specialization="";
$this->address="";
$this->Photo="";
$this->edit_photo="";

session()->flash('message', 'doctor Updated Successfully.');

$this->button_text = "Add New Docter";

}

public function delete($id)
{
$doctor = doctor::find($id);
Storage::disk('public')->delete($doctor->photo_path);
$doctor->delete();
session()->flash('message', 'doctor Deleted Successfully.');
}
public function render()
{
return view('livewire.admins.docter',[
'doctors'=>doctor::with(['docname'])->paginate(10),
'departments'=>department::with(['hod'])->get(),
])->layout('admins.layouts.app');
}
}
1 change: 1 addition & 0 deletions app/Http/Livewire/Admins/Hods.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function render()
{
if ($this->_page == "index") {
return view('livewire.admins.hod.hods', [
'doctors' => doctor::with(['employ'])->get(),
'hods' => hod::latest()->paginate(10),
])->layout('admins.layouts.app');
} else if ($this->_page == "create") {
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Livewire/Admins/Rooms.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function add_room()

ModelsRooms::create([
'department_id' => $this->department,
'roomtype' => $this->roomtype,
'available' => $this->available ? true:false,
'type' => $this->roomtype,
'status' => $this->available ? true:false,
]);

$this->department="";
Expand All @@ -52,8 +52,8 @@ public function edit($id)
$Room = ModelsRooms::findOrFail($id);
$this->edit_Room_id = $id;
$this->department = $Room->department_id;
$this->roomtype = $Room->roomtype;
$this->available = $Room->available ? 'checked' : '';
$this->roomtype = $Room->type;
$this->available = $Room->status ? 'checked' : '';

$this->button_text="Update Room";
}
Expand All @@ -67,8 +67,8 @@ public function update($id)

$Room = ModelsRooms::findOrFail($id);
$Room->department_id = $this->department;
$Room->roomtype = $this->roomtype;
$Room->available = $this->available ? true:false;
$Room->type = $this->roomtype;
$Room->status = $this->available ? true:false;

$Room->save();

Expand Down
9 changes: 6 additions & 3 deletions app/Models/department.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public function block(): BelongsTo
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function hod(): HasOne
// public function hod(): HasOne
// {
// return $this->hasOne(hod::class);
// }
public function hod(): BelongsTo
{
return $this->hasOne(hod::class);
return $this->BelongsTo(hod::class);
}

}
2 changes: 2 additions & 0 deletions app/Models/doctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public function employ(): BelongsTo
{
return $this->belongsTo(employee::class,'employee_id','id');
}


}
16 changes: 12 additions & 4 deletions resources/views/livewire/admins/departments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
<th>Name</th>
<th>Description</th>
<th>Photo</th>
<th>HOD ID</th>
<th>BlockID</th>
<th>HOD Name</th>
<th>Block Code</th>
<th>Created at</th>
<th>Actions</th>
</tr>
Expand All @@ -102,8 +102,16 @@
<td>{{ $department->name }}</td>
<td>{{ $department->description }}</td>
<td><img width="50px" height="50px" src="{{ $department->photo_path }}" alt=""></td>
<td>{{ $department->hod_id }}</td>
<td>{{ $department->block_id }}</td>
<td> @foreach($hods as $doc)
@if($doc->id == $department['hod']->doctor_id)
{{$doc['employ']->name}}
@endif
@endforeach </td>
<td> @foreach($blocks as $item_code)
@if($item_code->id==$department->block_id)
{{ $item_code->blockcode }}
@endif
@endforeach</td>
<td>{{ $department->created_at }}</td>
<td class="text-right">
<button class="btn btn-outline-info btn-rounded" wire:click.prevent="edit({{ $department->id }})"><i class="fas fa-pen"></i></button>
Expand Down
9 changes: 7 additions & 2 deletions resources/views/livewire/admins/hod/hods.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<thead>
<tr>
<th class="text-center">ID</th>
<th class="text-center">Doctor id</th>
<th class="text-center">Doctor Name</th>
<th class="text-center">Dated</th>
<th class="text-center">Actions</th>
</tr>
Expand All @@ -39,7 +39,12 @@
@forelse ($hods as $hod)
<tr>
<td class="text-center">{{ $hod->id }}</td>
<td class="text-center">{{ $hod->doctor->employ->name }}</td>
<td class="text-center">
@foreach($doctors as $doc)
@if($doc->id==$hod->doctor_id)
{{ $doc['employ']->name }}
@endif
@endforeach</td>
<td class="text-center">{{ $hod->created_at }}</td>
<td class="text-center">
<button wire:click="show_edit_form({{ $hod->id }})"
Expand Down
7 changes: 4 additions & 3 deletions resources/views/livewire/admins/rooms.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@error('roomtype')
<span class="text-red-500 text-danger text-xs">{{ $message }}</span>
@enderror

</div>
<div class="form-group">
<label for="available">Available</label>
Expand All @@ -64,7 +65,7 @@
<th>Room No</th>
<th>Room Type</th>
<th>Department</th>
<th>Avaialble</th>
<th>Available</th>
<th>Dated</th>
<th>Actions</th>
</tr>
Expand All @@ -73,9 +74,9 @@
@forelse ($rooms as $room)
<tr>
<td>{{ $room->id }}</td>
<td>{{ $room->roomtype }}</td>
<td>{{ $room->type }}</td>
<td>{{ $room->department->name }}</td>
<td>{{ $room->available }}</td>
<td>@if($room->status=='available')Yes @endif</td>
<td>{{ $room->created_at }}</td>
<td class="text-right">
<button wire:click="edit({{ $room->id }})"
Expand Down