Files
portal-api/app/Repositories/Ticket/TicketRepository.php
T
2026-09-28 08:26:29 +07:00

42 lines
1.2 KiB
PHP

<?php
namespace App\Repositories\Ticket;
use App\Models\Ticket;
use App\Repositories\BaseRepository;
class TicketRepository extends BaseRepository implements TicketRepositoryInterface
{
public function getModel()
{
return Ticket::class;
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
{
$model = $this->model->with($relationships)->select($select);
if (isset($data['status']) && ! empty($data['status']) && $data['status'] != 'full') {
$model = $model->where("status", match (strtolower($data['status'])) {
'pending' => 1,
'close' => 0,
default => 1
});
}
if (count($withCount) > 0) {
$model = $model->withCount($withCount);
}
if (isset($data['page']) && $data['page']) {
return $model->paginate(15);
}
return $model->get();
}
public function findBy(string $key = '', string $value)
{
if (empty($key) || empty($value)) {
return false;
}
return $this->model->where($key, $value)->first();
}
}