This commit is contained in:
pbao9
2025-07-29 17:31:45 +07:00
parent d80580d1e4
commit b048edee11
15 changed files with 382 additions and 16 deletions
@@ -0,0 +1,54 @@
<?php
namespace App\Repositories\Module\IPPool;
use App\Models\IPPool;
use App\Repositories\BaseRepository;
class IPPoolRepository extends BaseRepository implements IPPoolRepositoryInterface
{
public function getModel()
{
return IPPool::class;
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
{
$model = $this->model->with($relationships)->select($select);
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['page'])) {
return $model->paginate(15);
}
return $model->get();
}
public function findByName(string $name = '')
{
if (empty($name)) {
return false;
}
return $this->model->where('name','LIKE',"%$name%")->first();
}
}