Use same categories layout as in header search

This commit is contained in:
DariusIII
2026-05-14 12:50:41 +02:00
parent bd9aa517d3
commit 9003c572ef
3 changed files with 25 additions and 32 deletions
+2
View File
@@ -49,12 +49,14 @@ class AppServiceProvider extends ServiceProvider
// Share global data with layouts and all admin views
// Admin child views need direct registration because @section blocks
// are evaluated before the layout composer runs
// Same for search.* so category menu data (e.g. parentcatlist) exists in @section('content')
view()->composer([
'layouts.main',
'layouts.admin',
'layouts.guest',
'layouts.app',
'admin.*',
'search.*',
], GlobalDataComposer::class);
Gate::define('viewPulse', function (User $user) {
+10 -21
View File
@@ -66,6 +66,7 @@ class ReleaseSearchService
Log::debug('ReleaseSearchService::search called', [
'searchArr' => $searchArr,
'limit' => $limit,
'type' => $type,
]);
}
@@ -89,9 +90,7 @@ class ReleaseSearchService
}
}
$categoryIdsRaw = $type === 'basic'
? Category::getCategorySearch($cat, null, true)
: (((int) ($cat[0] ?? -1) !== -1) ? [(int) $cat[0]] : null);
$categoryIdsRaw = Category::getCategorySearch($cat, null, true);
$categoryIds = null;
if (is_array($categoryIdsRaw)) {
@@ -176,7 +175,6 @@ class ReleaseSearchService
$daysOld,
$maxAge,
$excludedCats,
$type,
$cat,
$minSize
);
@@ -1723,7 +1721,6 @@ class ReleaseSearchService
mixed $daysOld,
int $maxAge,
array $excludedCats,
string $type,
array $cat,
int $minSize
): string {
@@ -1755,7 +1752,7 @@ class ReleaseSearchService
}
// Category conditions - only add if not empty
$catQuery = $this->buildCategoryCondition($type, $cat);
$catQuery = $this->buildCategoryCondition($cat);
if (! empty($catQuery) && $catQuery !== '1=1') {
$conditions[] = $catQuery;
}
@@ -1851,26 +1848,18 @@ class ReleaseSearchService
}
/**
* Build category condition based on search type
* Build category condition for web search (basic and advanced).
*
* @param array<int|string, mixed> $cat Category IDs (list or associative)
*/
private function buildCategoryCondition(string $type, array $cat): string
private function buildCategoryCondition(array $cat): string
{
if ($type === 'basic') {
$catSearch = Category::getCategorySearch($cat);
// Remove WHERE and AND from the beginning as we're building it into a larger WHERE clause
$catSearch = preg_replace('/^(WHERE|AND)\s+/i', '', trim($catSearch));
$catSearch = Category::getCategorySearch($cat);
// Remove WHERE and AND from the beginning as we're building it into a larger WHERE clause
$catSearch = preg_replace('/^(WHERE|AND)\s+/i', '', trim((string) $catSearch));
// Don't return '1=1' as it's not needed
return ($catSearch === '1=1') ? '' : $catSearch;
}
if ($type === 'advanced' && (int) $cat[0] !== -1) {
return sprintf('r.categories_id = %d', (int) $cat[0]);
}
return '';
// Don't return '1=1' as it's not needed
return ($catSearch === '1=1') ? '' : $catSearch;
}
/**
+13 -11
View File
@@ -59,20 +59,22 @@
@if(isset($parentcatlist))
@foreach($parentcatlist as $parentcat)
@php
$parentId = is_object($parentcat) ? $parentcat->id : ($parentcat['id'] ?? '');
$parentTitle = is_object($parentcat) ? $parentcat->title : ($parentcat['title'] ?? 'Category');
$subcategories = is_object($parentcat) ? $parentcat->categories : ($parentcat['categories'] ?? []);
@endphp
<optgroup label="{{ $parentTitle }}">
@foreach($subcategories as $subcat)
@php
$subcatId = is_object($subcat) ? $subcat->id : ($subcat['id'] ?? '');
$subcatTitle = is_object($subcat) ? $subcat->title : ($subcat['title'] ?? '');
@endphp
<option value="{{ $subcatId }}" {{ request('t') == $subcatId ? 'selected' : '' }}>
{{ $subcatTitle }}
</option>
@endforeach
</optgroup>
<option value="{{ $parentId }}" class="font-semibold" {{ request('t') == $parentId ? 'selected' : '' }}>
{{ $parentTitle }}
</option>
@foreach($subcategories as $subcat)
@php
$subcatId = is_object($subcat) ? $subcat->id : ($subcat['id'] ?? '');
$subcatTitle = is_object($subcat) ? $subcat->title : ($subcat['title'] ?? '');
@endphp
<option value="{{ $subcatId }}" {{ request('t') == $subcatId ? 'selected' : '' }}>
&nbsp;&nbsp;{{ $subcatTitle }}
</option>
@endforeach
@endforeach
@elseif(isset($catlist))
@foreach($catlist as $catId => $catTitle)