You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
988 B

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\PublicSourceChannel;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class PublicSourceChannelController extends Controller
{
public function resolve(Request $request): JsonResponse
{
$sourceCode = trim((string) $request->query('source_code', ''));
if (! preg_match('/^[A-Za-z0-9_-]{2,64}$/', $sourceCode)) {
return response()->json(['valid' => false]);
}
$channel = PublicSourceChannel::query()
->where('source_code', $sourceCode)
->where('status', PublicSourceChannel::STATUS_ENABLED)
->first();
if ($channel === null) {
return response()->json(['valid' => false]);
}
return response()->json([
'valid' => true,
'source_code' => $channel->source_code,
'source_name' => $channel->source_name,
]);
}
}