Extract Ladill Servers as standalone app at servers.ladill.com.
VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Hosting;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CustomerHostingOrder;
|
||||
use App\Models\HostingProduct;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SearchController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$q = trim((string) $request->query('q', ''));
|
||||
|
||||
if (mb_strlen($q) < 2) {
|
||||
return response()->json(['results' => []]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'results' => $this->resultsForUser($request->user(), $q),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return list<array{type:string,title:string,subtitle:string,url:string}> */
|
||||
private function resultsForUser($user, string $q): array
|
||||
{
|
||||
$like = '%'.$q.'%';
|
||||
$results = [];
|
||||
$serverTypes = [HostingProduct::TYPE_VPS, HostingProduct::TYPE_DEDICATED];
|
||||
|
||||
CustomerHostingOrder::query()
|
||||
->forUser($user->id)
|
||||
->whereHas('product', fn ($query) => $query->whereIn('type', $serverTypes))
|
||||
->where(function ($query) use ($like) {
|
||||
$query->where('domain_name', 'like', $like)
|
||||
->orWhere('server_ip', 'like', $like);
|
||||
})
|
||||
->with('product')
|
||||
->orderByDesc('updated_at')
|
||||
->limit(12)
|
||||
->get()
|
||||
->each(function (CustomerHostingOrder $order) use (&$results): void {
|
||||
$panelUrl = $order->control_panel_url ?: route('servers.orders.show', $order);
|
||||
$results[] = [
|
||||
'type' => 'server',
|
||||
'title' => $order->domain_name ?: ($order->product?->name ?? 'Server #'.$order->id),
|
||||
'subtitle' => ($order->product?->name ?? 'Server').' · '.ucwords(str_replace('_', ' ', (string) $order->status)),
|
||||
'url' => $panelUrl,
|
||||
];
|
||||
});
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user