77 lines
2.2 KiB
PHP
77 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Consultation\app\Repositories;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\Consultation\app\Models\Consultation;
|
|
|
|
class ConsultationRepository
|
|
{
|
|
public function allConsultationList($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
|
|
{
|
|
return Consultation::when(array_keys($filter, true), function ($query) use ($filter) {
|
|
if (!empty($filter['contact_no'])) {
|
|
$query->where('contact_no', $filter['contact_no']);
|
|
}
|
|
})
|
|
->orderBy($sort['by'], $sort['sort'])
|
|
->paginate($perPage ?: env('PAGE_LIMIT', 999));
|
|
}
|
|
|
|
public function findConsultationListById($uuid)
|
|
{
|
|
return Consultation::where('uuid', $uuid)->first();
|
|
}
|
|
|
|
public function storeConsultationList($validated)
|
|
{
|
|
DB::beginTransaction();
|
|
try {
|
|
$consultation = new Consultation();
|
|
$consultation->uuid = Str::uuid();
|
|
$consultation->name = $validated['name'];
|
|
$consultation->email = $validated['email'] ?? null;
|
|
$consultation->contact_no = $validated['contact_no'];
|
|
$consultation->age_group = $validated['age_group'];
|
|
$consultation->procedure_of_interest = $validated['procedure_of_interest'];
|
|
$consultation->subject = $validated['subject'];
|
|
$consultation->message = $validated['message'];
|
|
$consultation->is_aggrement = $validated['is_aggrement'] ?? 10;
|
|
$consultation->save();
|
|
|
|
|
|
DB::commit();
|
|
|
|
return $consultation;
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
DB::rollback();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function deleteConsultationList($uuid)
|
|
{
|
|
DB::beginTransaction();
|
|
try {
|
|
$consultation = $this->findConsultationListById($uuid);
|
|
|
|
if (!$consultation) {
|
|
return null;
|
|
}
|
|
|
|
$consultation->delete();
|
|
DB::commit();
|
|
|
|
return true;
|
|
} catch (\Throwable $th) {
|
|
DB::rollback();
|
|
report($th);
|
|
return null;
|
|
}
|
|
}
|
|
}
|