Query a Single Type Document with Laravel

Here we discuss how to retrieve the content for a Single type document.

getSingle helper function

In this example we use the getSingle helper function to query the single instance of the custom type "navigation".

Copy
<?php
$document = $api->getSingle('navigation');
// $document contains the document content

Without the helper

You can perform the same query without using the helper function. Here we again query the single document of the type "navigation".

Copy
<?php
$response = $api->query(Predicates::at('document.type', 'navigation'));
$document = $response->results[0];
// $document contains the document content

Querying by Language

Note that if you are trying to query a document that isn't in the master language of your repository this way, you will need to specify the language code or wildcard language value. You can read how to do this on theĀ Query by Language page.

If you are using the query helper function above, you do not need to do this.