Collection Queries
You can access the items of a Collection in your templates (or anywhere else) by using the collection helper. The helper returns an Eloquent collection of Block objects that you can iterate over.
Basic usage
Retrieve all entries of a collection by passing the collection handle as the first argument.
@foreach (collection('my_collection') as $block)
<h2>{{ $block->_title }}</h2>
<p>{{ $block->_content }}</p>
@endforeachRead more about accessing field data in the Blocks documentation.
Using the query builder
The collection helper returns all entries of a collection. In order to work with the underlying query builder instance, you can use the collection_query helper.
Use the custom whereField, whereFieldIn, and orderByField methods to filter and sort the collection data.
$blocks = collection_query('my_collection')
->whereField('type', 'main')
->orderByField('title')
->get();TIP
Using collection_query is more efficient when you only need to fetch a subset of the collection data or want to apply filters, sorting, or pagination.