82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Appointment\app\Repositories;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\Appointment\app\Models\Appointment;
|
|
|
|
class AppointmentRepository
|
|
{
|
|
public function allAppointmentList($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
|
|
{
|
|
return Appointment::with('doctorDetail')->when(array_keys($filter, true), function ($query) use ($filter) {
|
|
if (!empty($filter['email'])) {
|
|
$query->where('email', $filter['email']);
|
|
}
|
|
})
|
|
->orderBy($sort['by'], $sort['sort'])
|
|
->paginate($perPage ?: env('PAGE_LIMIT', 999));
|
|
}
|
|
|
|
public function findAppointmentListById($uuid)
|
|
{
|
|
return Appointment::where('uuid', $uuid)->first();
|
|
}
|
|
|
|
public function storeAppointmentList($validated)
|
|
{
|
|
DB::beginTransaction();
|
|
try {
|
|
$appointment = new Appointment();
|
|
$appointment->uuid = Str::uuid();
|
|
$appointment->team_member_id = $validated['team_member_id'];
|
|
$appointment->full_name = $validated['full_name'];
|
|
$appointment->email = $validated['email'];
|
|
$appointment->contact_no = $validated['contact_no'];
|
|
$appointment->subject = $validated['subject'];
|
|
$appointment->feedback = $validated['feedback'];
|
|
if($appointment->save()) {
|
|
$from = $appointment->email;
|
|
$to = "info@aroginhealthcare.com";
|
|
$subject = $appointment->subject;
|
|
$message = $appointment->feedback;
|
|
$headers = "From:" . $from;
|
|
mail($to,$subject,$message, $headers);
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
|
|
return $appointment;
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
DB::rollback();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function deleteAppointmentList($uuid)
|
|
{
|
|
DB::beginTransaction();
|
|
try {
|
|
$appointment = $this->findAppointmentListById($uuid);
|
|
|
|
if (!$appointment) {
|
|
return null;
|
|
}
|
|
|
|
$appointment->delete();
|
|
DB::commit();
|
|
|
|
return true;
|
|
} catch (\Throwable $th) {
|
|
DB::rollback();
|
|
report($th);
|
|
return null;
|
|
}
|
|
}
|
|
}
|