PHP code example of webhappens / prismic

1. Go to this page and download the library: Download webhappens/prismic library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webhappens / prismic example snippets




namespace App;

use WebHappens\Prismic\Document;

class Article extends Document
{
    /**
     * The 'API ID' of the Custom Type associated with the document model.
     *
     * @var string
     */
    protected static $type = 'article';
}

use App\Article;
use WebHappens\Prismic\Prismic;

public function register()
{
    Prismic::documents([
        Article::class,
    ]);
}

// Retrieve all Article Documents
$articles = Article::all();

// Process each Article in chunks of 100
Article::chunk(100, function ($articles) {
    foreach ($articles as $article) {
        //
    }
});

// Retrive the Article with an ID of WAjgAygABN3B0a-a
$article = Article::find('WAjgAygABN3B0a-a');

// Retrieve a Single Type Document
$homepage = Homepage::single();