57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\DomainFluctuation\App\Http\Controllers\Api\Client;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Modules\DomainFluctuation\App\Http\Requests\IndexDomainFluctuationRequest;
|
|
use Modules\DomainFluctuation\App\Http\Resources\DomainFluctuationResource;
|
|
use Modules\DomainFluctuation\App\Models\DomainFluctuation;
|
|
|
|
class DomainFluctuationController extends Controller
|
|
{
|
|
public function index(IndexDomainFluctuationRequest $request): JsonResponse
|
|
{
|
|
$filter = $request->toDTO();
|
|
|
|
$query = DomainFluctuation::query()
|
|
->with('term')
|
|
->where('status', 1);
|
|
|
|
if ($filter->termId) {
|
|
$query->where('term_id', $filter->termId);
|
|
}
|
|
|
|
if ($filter->keyword) {
|
|
$kw = '%' . $filter->keyword . '%';
|
|
$query->where(function ($q) use ($kw) {
|
|
$q->where('domainName', 'like', $kw)
|
|
->orWhere('ownerName', 'like', $kw);
|
|
});
|
|
}
|
|
|
|
$query->orderBy($filter->sortBy, $filter->sortDir);
|
|
|
|
$paginator = $query->paginate($filter->perPage, ['*'], 'page', $filter->page);
|
|
|
|
return DomainFluctuationResource::collection($paginator)->response();
|
|
}
|
|
|
|
public function show(int $id): JsonResponse
|
|
{
|
|
$domain = DomainFluctuation::with('term')->where('status', 1)->find($id);
|
|
|
|
if (! $domain) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Không tìm thấy tên miền',
|
|
], 404);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => DomainFluctuationResource::make($domain),
|
|
]);
|
|
}
|
|
}
|