firstcommit
This commit is contained in:
103
Modules/FAQ/app/Repositories/FaqRepository.php
Normal file
103
Modules/FAQ/app/Repositories/FaqRepository.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\FAQ\app\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\FAQ\app\Models\Faq;
|
||||
|
||||
class FaqRepository
|
||||
{
|
||||
//-- Retrieve all Services
|
||||
public function allfaqs($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
|
||||
{
|
||||
return Faq::when(array_keys($filter, true), function ($query) use ($filter) {
|
||||
if (! empty($filter['question'])) {
|
||||
$query->where('question', $filter['question']);
|
||||
}
|
||||
if (! empty($filter['answer'])) {
|
||||
$query->where('answer', 'like', '%'.$filter['answer'].'%');
|
||||
}
|
||||
})
|
||||
->orderBy($sort['by'], $sort['sort'])
|
||||
->paginate($perPage ?: env('PAGE_LIMIT', 999));
|
||||
}
|
||||
|
||||
//-- Find Service by uuid
|
||||
public function findFaqByUuid($uuid)
|
||||
{
|
||||
return Faq::where('uuid', $uuid)->first();
|
||||
}
|
||||
|
||||
public function storeFaq(array $validated)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$faq = new Faq();
|
||||
$faq->uuid = Str::uuid();
|
||||
$faq->question = $validated['question'];
|
||||
$faq->answer = $validated['answer'];
|
||||
$faq->ordering = $validated['ordering'];
|
||||
$faq->status = $validated['status'];
|
||||
$faq->save();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $faq;
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollback();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateFaq($validated, $uuid)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$faq = $this->findFaqByUuid($uuid);
|
||||
|
||||
if (! $faq) {
|
||||
return null;
|
||||
}
|
||||
$faq->question = $validated['question'];
|
||||
$faq->answer = $validated['answer'];
|
||||
$faq->ordering = $validated['ordering'];
|
||||
$faq->ordering = $validated['ordering'];
|
||||
$faq->status = $validated['status'];
|
||||
$faq->save();
|
||||
|
||||
return $faq;
|
||||
DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollBack();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//-- Delete Testimonial
|
||||
public function deleteFaq(string $uuid)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$faq = $this->findFaqByUuid($uuid);
|
||||
if (! $faq) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$faq->delete();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $faq;
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollBack();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user