Files
2026-09-12 21:04:45 +01:00

48 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\DjProfile;
use Illuminate\Http\Request;
use Illuminate\View\View;
class DjController extends Controller
{
public function index(Request $request): View
{
$query = DjProfile::query()->where('is_published', true)->with('genres');
if ($request->filled('location')) {
$query->where('city', 'like', '%'.$request->string('location').'%');
}
if ($request->filled('max_price')) {
$query->where('price_from', '<=', $request->integer('max_price'));
}
$query->orderByDesc('is_featured');
match ($request->string('sort')->toString()) {
'price_low' => $query->orderBy('price_from'),
'price_high' => $query->orderByDesc('price_from'),
default => $query->orderByDesc('average_rating'),
};
return view('djs.index', ['djs' => $query->paginate(12)->withQueryString()]);
}
public function show(DjProfile $djProfile): View
{
abort_unless($djProfile->is_published, 404);
return view('djs.show', [
'dj' => $djProfile->load(['genres', 'reviews' => fn ($query) => $query->where('status', 'published')->latest()]),
]);
}
public function apiIndex()
{
return DjProfile::where('is_published', true)->with('genres')->paginate(20);
}
}