Files
backend/app/Http/Controllers/Api/V1/EstablishmentController.php
T
2026-06-28 12:29:53 +02:00

42 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Concerns\RespondsWithJson;
use App\Http\Resources\EstablishmentResource;
use App\Models\Establishment;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class EstablishmentController extends Controller
{
use RespondsWithJson;
public function index(Request $request): JsonResponse
{
$establishments = Establishment::query()
->where('is_active', true)
->when($request->filled('city'), fn ($q) => $q->where('city', $request->string('city')->toString()))
->orderBy('name')
->get();
return $this->success([
'establishments' => EstablishmentResource::collection($establishments),
]);
}
public function show(string $uuid): JsonResponse
{
$establishment = Establishment::query()
->where('uuid', $uuid)
->where('is_active', true)
->with(['machines' => fn ($q) => $q->orderBy('name')])
->firstOrFail();
return $this->success([
'establishment' => new EstablishmentResource($establishment),
]);
}
}