Fluent Wrapper Overview
The fluent warpper wraps the official Prismic PHP Kit and provides the following benifits:
- A much cleaner fluent API.
- Automatic relationship resolution.
- Arrayable and Jasonable responses with relationship resolution.
- The ability to switch back to the official Prismic PHP Kit's API at any point.
Note: All examples provided on the page will use the Laravel API for brevity. See Getting Started: Vanilla PHP for an initalizing the fluent wrapper outside of Laravel.
Making requests
The wrapper overloads to official Prismic PHP Kit to make requests, so refer to it for documentation on querying prismic.
Prismic::getByID('WAjgAygABN3B0a-a')
->title
or for more complex queries, you can still use Predicates.
Prismic::query(
Predicates::at('document.tags', ['featured'])
)
->first()
->title
Using the official API while chaining
You can easily resolve native API objects at any time using the getRaw
or getObject
methods. This could be useful if you want ot override the fluent API's functionality to use the official API instead.
getRaw
Fetches an objects attribute as a official API object.
Prismic::getByID('WAjgAygABN3B0a-a')->author->getRaw('first_name')->asText();
getObject
Fetches the object that the fluent object is wrapping.
Prismic::getByID('WAjgAygABN3B0a-a')->author->getObject()->getStructuredText('author.first_name')->asText();