Availability Search for Multiple Entries
This page shows how to list every entry that’s available for the searched dates, like all the rooms free next weekend.
There are three ways to do it:
| You want | Use |
|---|---|
| A list that updates as visitors search (recommended) | The availability-collection component |
| A plain list that reloads the page | The Collection Tag |
| Availability as one filter among others, like amenities or price | Livewire Filters |
For a single entry, see Availability Results, Availability List or Cart Booking.
The availability-collection component
The availability-collection component shows a card for each available entry, with its price and a booking button. It updates whenever the visitor changes the availability-search next to it.
Use it with a collection, with a list of entry IDs, or with both to show only those entries from the collection. You need at least one of the two.
<livewire:availability-search />
<livewire:availability-collection collection="rooms" />
<livewire:availability-collection :entries="['id-1', 'id-2', 'id-3']" />
With rates, prices sorted cheapest first, and 12 entries per page:
<livewire:availability-search :rates="true" :any-rate="true" />
<livewire:availability-collection
collection="rooms"
:rates="true"
:show-rates="true"
sort="price"
:paginate="12"
/>
Properties
| Property | Default | Description |
|---|---|---|
collection |
The collection’s handle. | |
entries |
[] |
Entry IDs. With collection, only these entries from it are shown. |
rates |
false |
Show rate labels. |
showRates |
false |
List every available rate per entry, each with its price and button. Otherwise each entry shows one “from” price. |
showUnavailable |
false |
Also show sold out entries, marked “No availability”. |
paginate |
Entries per page. | |
sort |
order |
How entries are ordered: order (the collection’s order), title or price (cheapest first). |
rateSorting |
order |
How each entry’s rates are ordered: order (as in Rates) or price. The first rate gives the “from” price. |
overrideRates |
[] |
Your own rate_id => label map for rate labels. |
view |
availability-collection |
A custom view. |
With paginate, prices are checked one page at a time, so sort="price" sorts within each page.
When a visitor books
If the entry has its own page, the visitor goes there, and the page’s availability-results already has their dates. If it doesn’t, Resrv creates the reservation and takes them straight to checkout.
Cutoff rules aren’t checked in the list, only when the visitor books.
Customizing the view
Publish the views:
php artisan vendor:publish --tag=resrv-checkout-views
Then edit resources/views/vendor/statamic-resrv/livewire/availability-collection.blade.php, or set your own with view="my-view". The view gets:
$this->rows: one row per entry, with itsid,entry,available, itsfromrate, and every available rate inrates. Each rate hasprice,original_price,payment,rate_id,rateLabelandcancellation_policy.$this->resolvedEntries: the entries. Call->links()on it to show the page links when you paginate.$data: the visitor’s search, like$data->datesand$data->quantity.
To show a rate’s cancellation terms, pass its cancellation_policy to CancellationPolicy::labelFor().
Alternative approaches
Collection Tag (server-rendered)
If you don’t need the list to update live, use Statamic’s Collection Tag with the resrv_search query scope. It leaves out the entries that aren’t available:
<div class="w-96">
{{ livewire:availability-search calendar="range" live="false" :redirectTo="url" }}
</div>
{{ collection:rooms as="rooms" query_scope="resrv_search" resrv_search:resrv_availability="{ session:resrv-search }" }}
{{ if no_results }}
<p>No rooms are available for these dates.</p>
{{ /if }}
{{ rooms }}
<a href="{{ url }}">{{ title }}</a>
{{ /rooms }}
{{ /collection:rooms }}
When the visitor presses Search, the page reloads with only the available rooms. Always pass the search from the session, as above (resrv_search:resrv_availability="{ session:resrv-search }").
Livewire Filters (filtering beyond dates)
Livewire Filters, our add-on for filtering Statamic collections, lets visitors filter by almost any field. Use it when availability is one filter among others, like amenities or price.
Once you install Livewire Filters (reachweb/statamic-livewire-filters), Resrv adds an lf-availability-filter component. It works like availability-search, plus a blueprint set to collection.blueprint:
<div class="w-96">
{{ livewire:lf-availability-filter
blueprint="rooms.room"
calendar="range"
enableQuantity="true"
:rates="true"
}}
</div>
{{ livewire-collection:rooms query_scope="resrv_search" resrv_search:resrv_availability="{ session:resrv-search }" }}
Leave out :rates="true" if your entries don’t use Rates. To change how entries look, edit the Livewire Filters view at resources/views/vendor/statamic-livewire-filters/livewire/livewire-collection.antlers.html. See the Livewire Filters docs for the rest.
Accessing availability data
With both the Collection Tag and Livewire Filters, each available entry gets a live_availability value with:
| Property | Description |
|---|---|
price |
The total price for the searched dates. |
original_price |
The price before dynamic pricing. |
payment |
What the visitor pays now. |
rate_id and rateLabel |
The rate and its label, with rates. |
cancellation_policy |
The rate’s cancellation terms. |
{{ rooms }}
<a href="{{ url }}">
{{ title }}
{{ if live_availability }}
<span>Price: ${{ live_availability:price }}</span>
{{ /if }}
</a>
{{ /rooms }}
When an entry has several available rates, live_availability holds one row per rate, so loop over it.
Related
- Availability Search component: the search settings these share.
- Rates: selling an entry at different prices or terms.
- Availability Results, Availability List and Cart Booking: the components for one entry.