firstcommit

This commit is contained in:
2025-08-17 16:23:14 +05:45
commit 76bf4c0a18
2648 changed files with 362795 additions and 0 deletions

View 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;
}
}
}