mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 06:56:15 +00:00
Add app command/search (#622)
This commit is contained in:
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Spatie\RouteAttributes\Attributes\Get;
|
||||
use Spatie\RouteAttributes\Attributes\Middleware;
|
||||
use Spatie\RouteAttributes\Attributes\Prefix;
|
||||
@ -21,8 +23,65 @@ public function search(Request $request): JsonResponse
|
||||
|
||||
$query = $request->input('query');
|
||||
|
||||
$projects = DB::table('projects')
|
||||
->select(
|
||||
DB::raw('projects.id as id'),
|
||||
DB::raw('null as parent_id'),
|
||||
DB::raw('projects.name as label'),
|
||||
DB::raw('"project" as type')
|
||||
)
|
||||
->where(function (Builder $query) {
|
||||
if (! user()->isAdmin()) {
|
||||
$query
|
||||
->join('user_project', 'projects.id', '=', 'user_project.project_id')
|
||||
->where('user_project.user_id', user()->id);
|
||||
}
|
||||
})
|
||||
->where('projects.name', 'like', "%{$query}%");
|
||||
|
||||
$servers = DB::table('servers')
|
||||
->select(
|
||||
DB::raw('servers.id as id'),
|
||||
DB::raw('null as parent_id'),
|
||||
DB::raw('servers.name as label'),
|
||||
DB::raw('"server" as type')
|
||||
)
|
||||
->join('projects', 'servers.project_id', '=', 'projects.id')
|
||||
->where(function (Builder $query) {
|
||||
if (! user()->isAdmin()) {
|
||||
$query
|
||||
->join('user_project', 'projects.id', '=', 'user_project.project_id')
|
||||
->where('user_project.user_id', user()->id);
|
||||
}
|
||||
})
|
||||
->where('servers.name', 'like', "%{$query}%");
|
||||
|
||||
$sites = DB::table('sites')
|
||||
->select(
|
||||
DB::raw('sites.id as id'),
|
||||
DB::raw('sites.server_id as parent_id'),
|
||||
DB::raw('sites.domain as label'),
|
||||
DB::raw('"site" as type')
|
||||
)
|
||||
->join('servers', 'sites.server_id', '=', 'servers.id')
|
||||
->join('projects', 'servers.project_id', '=', 'projects.id')
|
||||
->where(function (Builder $query) {
|
||||
if (! user()->isAdmin()) {
|
||||
$query
|
||||
->join('user_project', 'projects.id', '=', 'user_project.project_id')
|
||||
->where('user_project.user_id', user()->id);
|
||||
}
|
||||
})
|
||||
->where('sites.domain', 'like', "%{$query}%");
|
||||
|
||||
// Combine with unionAll
|
||||
$results = $projects
|
||||
->unionAll($servers)
|
||||
->unionAll($sites)
|
||||
->get();
|
||||
|
||||
$results = [
|
||||
'data' => [], // Replace with actual search results
|
||||
'data' => $results, // Replace with actual search results
|
||||
];
|
||||
|
||||
return response()->json($results);
|
||||
|
@ -14,7 +14,6 @@
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
@ -93,18 +92,6 @@ public function switch(Server $server): RedirectResponse
|
||||
{
|
||||
$this->authorize('view', $server);
|
||||
|
||||
$previousUrl = URL::previous();
|
||||
$previousRequest = Request::create($previousUrl);
|
||||
$previousRoute = app('router')->getRoutes()->match($previousRequest);
|
||||
|
||||
if ($previousRoute->hasParameter('server')) {
|
||||
if (count($previousRoute->parameters()) > 1) {
|
||||
return redirect()->route('servers.show', ['server' => $server->id]);
|
||||
}
|
||||
|
||||
return redirect()->route($previousRoute->getName(), ['server' => $server]);
|
||||
}
|
||||
|
||||
return redirect()->route('servers.show', ['server' => $server->id]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user