Files
2025-07-24 16:18:27 +07:00

56 lines
1.9 KiB
PHP

<?php
namespace App\Repositories\Log;
use App\Models\Log;
use App\Repositories\BaseRepository;
class LogRepository extends BaseRepository implements LogRepositoryInterface
{
public function getModel()
{
return Log::class;
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
{
$model = $this->model->with($relationships)->select($select);
if (isset($data['customer_id'])) {
$model = $model->where("customer_id", $data['customer_id']);
}
if (isset($data['relations'])) {
foreach ($data['relations'] as $key => $value) {
$model = $model->whereHas($key, function ($query) use ($value) {
if (isset($value['condition'])) {
switch (strtoupper($value['condition'])) {
case "IN":
$query->whereIn($value['key'], $value['value']);
break;
case "NotIn":
$query->whereNotIn($value['key'], $value['value']);
break;
default:
$query->where($value['key'], $value['condition'], $value['value']);
break;
}
} else {
$query->where($value['key'], $value['value']);
}
});
}
}
if (count($withCount) > 0) {
$model = $model->withCount($withCount);
}
if(isset($data['limit']))
{
return $model->latest('id')->take($data['limit'])->get();
}
if(isset($data['page'])) {
return $model->latest('id')->paginate(15);
}
return $model->latest('id')->get();
}
}