feat: implement search functionality in MusicProductionController, enhance view with search form and localization support for search results

This commit is contained in:
Ümit Tunç
2026-05-20 23:13:21 +03:00
parent 276e4b30ca
commit 33c7b6a51e
4 changed files with 50 additions and 5 deletions
@@ -19,10 +19,28 @@ class MusicProductionController extends Controller
$settings->{$setting->key} = $setting->value;
}
// Get active music productions
$productions = MusicProduction::active()
->ordered()
->paginate(9); // Using 9 for nice grid layout (3 per row)
$search = trim((string) request('q', ''));
$productionsQuery = MusicProduction::active()->ordered();
if ($search !== '') {
$locale = app()->getLocale();
$productionsQuery->where(function ($query) use ($search, $locale) {
$query->where('title', 'like', "%{$search}%")
->orWhere('client_name', 'like', "%{$search}%")
->orWhere('slug', 'like', "%{$search}%")
->orWhereHas('translations', function ($translationQuery) use ($search, $locale) {
$translationQuery
->where('status', 'published')
->whereIn('field_name', ['title', 'client_name', 'content'])
->where('field_value', 'like', "%{$search}%")
->where('language_code', $locale);
});
});
}
$productions = $productionsQuery->paginate(9)->withQueryString();
// --- Footer Logic ---
$renderedFooter = null;
@@ -50,6 +68,7 @@ class MusicProductionController extends Controller
return view('front.music-productions.index', [
'productions' => $productions,
'search' => $search,
'settings' => $settings,
'header' => 'partials.header-center-nav',
'renderedFooter' => $renderedFooter,