Files
beatbook/app/Http/Controllers/DjController.php
T
2026-09-12 20:21:11 +01:00

34 lines
1013 B
PHP

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