75 lines
2.0 KiB
PHP
75 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\ContactUs\app\Repositories;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\ContactUs\app\Models\ContactUs;
|
|
|
|
class ContactUsRepository
|
|
{
|
|
public function allContactList($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
|
|
{
|
|
return ContactUs::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 findContactUsListById($uuid)
|
|
{
|
|
return ContactUs::where('uuid', $uuid)->first();
|
|
}
|
|
|
|
public function storeContactUsList($validated)
|
|
{
|
|
DB::beginTransaction();
|
|
try {
|
|
$contact_us = new ContactUs();
|
|
$contact_us->uuid = Str::uuid();
|
|
$contact_us->full_name = $validated['full_name'];
|
|
$contact_us->address = $validated['address'] ?? null;
|
|
$contact_us->email = $validated['email'] ?? null;
|
|
$contact_us->phone = $validated['phone'];
|
|
$contact_us->subject = $validated['subject'] ?? null;
|
|
$contact_us->message = $validated['message'];
|
|
$contact_us->save();
|
|
|
|
|
|
DB::commit();
|
|
|
|
return $contact_us;
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
DB::rollback();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function deleteContactUsList($uuid)
|
|
{
|
|
DB::beginTransaction();
|
|
try {
|
|
$contact_us = $this->findContactUsListById($uuid);
|
|
|
|
if (!$contact_us) {
|
|
return null;
|
|
}
|
|
|
|
$contact_us->delete();
|
|
DB::commit();
|
|
|
|
return true;
|
|
} catch (\Throwable $th) {
|
|
DB::rollback();
|
|
report($th);
|
|
return null;
|
|
}
|
|
}
|
|
}
|