Update source into github
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\HostingServer;
|
||||
|
||||
use App\Models\ModuleHostingServer;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class HostingServerRepository extends BaseRepository implements HostingServerRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return ModuleHostingServer::class;
|
||||
}
|
||||
public function get_active()
|
||||
{
|
||||
return $this->model->isActive();
|
||||
}
|
||||
public function findByName(string $name = '')
|
||||
{
|
||||
if (empty($name)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where('name','LIKE',"%$name%")->first();
|
||||
}
|
||||
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'])) {
|
||||
if (is_array($data['status'])) {
|
||||
$model = $model->where(function ($query) use ($data) {
|
||||
if (isset($data['status']['condition'])) {
|
||||
switch (strtoupper($data['status']['condition'])) {
|
||||
case "IN":
|
||||
$query->whereIn($data['status']['key'], $data['status']['value']);
|
||||
break;
|
||||
case "NOTIN":
|
||||
$query->whereNotIn($data['status']['key'], $data['status']['value']);
|
||||
break;
|
||||
default:
|
||||
$query->where($data['status']['key'], $data['status']['condition'], $data['status']['value']);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$query->where($data['status']['key'], $data['status']['value']);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$model = $model->where("status", $data['status']);
|
||||
}
|
||||
}
|
||||
if (count($withCount) > 0) {
|
||||
$model = $model->withCount($withCount);
|
||||
}
|
||||
if (isset($data['page'])) {
|
||||
return $model->paginate(15);
|
||||
}
|
||||
return $model->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user