update deploy
This commit is contained in:
48
app/Repositories/Eloquent/FaqRepository.php
Normal file
48
app/Repositories/Eloquent/FaqRepository.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Eloquent;
|
||||
|
||||
use App\Enums\FaqCategory;
|
||||
use App\Models\Faq;
|
||||
use App\Repositories\Contracts\FaqRepositoryInterface;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* @extends BaseRepository<Faq>
|
||||
*/
|
||||
class FaqRepository extends BaseRepository implements FaqRepositoryInterface
|
||||
{
|
||||
public function __construct(Faq $model)
|
||||
{
|
||||
parent::__construct($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $filters
|
||||
* @return LengthAwarePaginator<int, Faq>
|
||||
*/
|
||||
public function paginate(array $filters = [], int $perPage = 15): LengthAwarePaginator
|
||||
{
|
||||
$query = $this->model->newQuery();
|
||||
|
||||
if (! empty($filters['category'])) {
|
||||
$query->where('category', $filters['category']);
|
||||
}
|
||||
|
||||
return $query->orderBy('order_index')->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Faq>
|
||||
*/
|
||||
public function getByCategory(FaqCategory $category): Collection
|
||||
{
|
||||
return Cache::remember("faqs.{$category->value}", 3600, fn () => $this->model->newQuery()
|
||||
->where('category', $category)
|
||||
->where('is_active', true)
|
||||
->orderBy('order_index')
|
||||
->get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user