50 lines
1.9 KiB
PHP
50 lines
1.9 KiB
PHP
<?php
|
|
namespace App\Repositories\Module\Domain;
|
|
|
|
use App\Models\ModuleDomain;
|
|
use App\Repositories\BaseRepository;
|
|
|
|
class DomainRepository extends BaseRepository implements DomainRepositoryInterface{
|
|
public function getModel()
|
|
{
|
|
return ModuleDomain::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 (isset($data['status'])) {
|
|
$model = $model->where("status", $data['status']);
|
|
}
|
|
if (isset($data['customer_id'])) {
|
|
$model = $model->where('customer_id', $data['customer_id']);
|
|
}
|
|
if (count($withCount) > 0) {
|
|
$model = $model->withCount($withCount);
|
|
}
|
|
if(isset($data['page'])) {
|
|
return $model->paginate(15);
|
|
}
|
|
return $model->get();
|
|
}
|
|
} |