initial commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user