Files
portal-api/app/Http/Controllers/frontend/Whois/WhoisController.php
T
2025-07-24 16:18:27 +07:00

89 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\frontend\Whois;
use App\Http\Controllers\Controller;
use App\Http\Requests\WhoisRequest;
use App\Services\WhoisService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Exception;
class WhoisController extends Controller
{
protected $whoisService;
public function __construct(WhoisService $whoisService)
{
$this->whoisService = $whoisService;
}
public function index()
{
return view('frontend.whois.index');
}
/**
* Get domain whois information
*
* @param WhoisRequest $request
* @return JsonResponse
*/
public function getDomainInfo(WhoisRequest $request): JsonResponse
{
try {
$domain = $request->validated()['domain'];
$data = $this->whoisService->getDomainInfo($domain);
return response()->json([
'success' => true,
'message' => __('Domain information retrieved successfully.'),
'data' => $data
], 200);
} catch (Exception $e) {
return response()->json([
'success' => false,
'message' => __('Failed to retrieve domain information.'),
'errors' => [
'domain' => [$e->getMessage()]
]
], 400);
}
}
/**
* Check if domain is available
*
* @param WhoisRequest $request
* @return JsonResponse
*/
public function checkAvailability(WhoisRequest $request): JsonResponse
{
try {
$domain = $request->validated()['domain'];
$isAvailable = $this->whoisService->isDomainAvailable($domain);
$status = $this->whoisService->getDomainStatus($domain);
return response()->json([
'success' => true,
'message' => __('Domain availability checked successfully.'),
'data' => [
'domain' => $domain,
'available' => $isAvailable,
'status' => $status
]
], 200);
} catch (Exception $e) {
return response()->json([
'success' => false,
'message' => __('Failed to check domain availability.'),
'errors' => [
'domain' => [$e->getMessage()]
]
], 400);
}
}
}