-
app/Models/Reservation.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Reservation extends Model { const STATUS_ACTIVE = 1; const STATUS_CANCELLED = 2; // }
-
app/Http/Controllers/OfficeController.php
Open in GitHubuse App\Http\Resources\OfficeResource; use App\Models\Office; use App\Models\Reservation; use Illuminate\Http\Resources\Json\JsonResource; class OfficeController extends Controller { // public function show(Office $office): JsonResource { $office->loadCount(['reservations' => fn($builder) => $builder->where('status', Reservation::STATUS_ACTIVE)]) ->load(['images', 'tags', 'user']); return OfficeResource::make($office); } // }