feat: Implement DNS management with dedicated models, repositories, requests, controllers, and services, while refactoring authentication by removing Passport and Sanctum.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\DnsManager\Domain;
|
||||
|
||||
use App\Models\DnsDomain;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class DnsDomainRepository extends BaseRepository implements DnsDomainRepositoryInterface
|
||||
{
|
||||
public function getModel(): string
|
||||
{
|
||||
return DnsDomain::class;
|
||||
}
|
||||
|
||||
public function findDomain(string $domain = '')
|
||||
{
|
||||
return $this->model->where('domain_name', $domain)->first();
|
||||
}
|
||||
|
||||
public function filter(array $data = [], array $relationships = [], string $order = 'id', array $select = ['*'])
|
||||
{
|
||||
$model = $this->model;
|
||||
|
||||
if (count($relationships)) {
|
||||
$model = $model->with($relationships);
|
||||
}
|
||||
|
||||
if (isset($data['q']) && $data['q']) {
|
||||
$model = $model->where('domain_name', 'like', '%' . $data['q'] . '%');
|
||||
}
|
||||
|
||||
if (isset($data['search']['value']) && $data['search']['value']) {
|
||||
$model = $model->where('domain_name', 'like', '%' . $data['search']['value'] . '%');
|
||||
}
|
||||
|
||||
if (isset($data['user_id']) && $data['user_id']) {
|
||||
$model = $model->whereHas('users', function ($query) use ($data) {
|
||||
$query->where('users.id', $data['user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($data['limit']) && !isset($data['page']) && $data['limit']) {
|
||||
$model = $model->take($data['limit']);
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
} else {
|
||||
$query->where($value['key'], $value['value']);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$model = $model->select($select)->orderByDesc($order);
|
||||
|
||||
if (isset($data['start'])) {
|
||||
return $model->offset($data['start'])->limit($data['length'] ?? 10)->get();
|
||||
}
|
||||
|
||||
if (isset($data['page'])) {
|
||||
return $model->paginate($data['length'] ?? 12);
|
||||
}
|
||||
|
||||
return $model->get();
|
||||
}
|
||||
|
||||
public function findWhereIn(string $key, array $value = [])
|
||||
{
|
||||
return $this->model->whereIn($key, $value)->get();
|
||||
}
|
||||
|
||||
public function findWithRelations(int $id, array $relationships = [])
|
||||
{
|
||||
return $this->model->with($relationships)->find($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user