Query builder
Basic query methods
Lets use the Page model from the previous chapter and query the api. We assume you created some base fields like a title, slug, and body.
single
Returns a model of a single content type.
find
First create a page with with the 'uid' field set to 'test' and publish it.
findById
findByIds
first
Return the first occurrence
all
Query all the documents of the page type.
paginate
The paginate methods works the same like the default Laravel paginate method.
where
Prismic Eloquent will automatically check if the field is a document based field or a user created field.
whereIn
whereNot
whereTag
Query the api based on a document tag.
whereTags
Query the api based on multiple document tags.
whereLanguage
orderBy
select
Specify the fields to select from the database.
Relationships
hasOne
You can specify a method on the model that returns a hasOne relation. The first parameter is the related model name and the second one the field. There is also a third parameter called parent. This can be used on fields like slices to specify any other object then the current model.
hasMany
You can specify a method on the model that returns a hasMany relation. The first parameter is the related model name and the second one the group name and the third one is the field.
Multiple models types
You can also define multiple model types since Prismic allows a content relation field to be of more then one content type.
Eager loading
Prismic also offers an option to eager load fields through the fetch links options.
Not all fields are supported for eager loading (fetching). Please review this in the Prismic documentation.
Note that only the fields specified are loaded.
Related content in slices
You can use the same method as above to load content inside slices.
Last updated