PHP code example of distilleries / contentful

1. Go to this page and download the library: Download distilleries/contentful 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/ */

    

distilleries / contentful example snippets


    class TerritoryMapper extends ContentfulMapper
    {
        /**
         * {@inheritdoc}
         */
        protected function map(array $entry, string $locale): array
        {
            $payload = $this->mapPayload($entry, $locale);
    
            return [
                'slug' => isset($payload['slug']) ? Caster::string($payload['slug']) : '',
                'title' => isset($payload['title']) ? Caster::string($payload['title']) : '',
            ];
        }
    }

    class Territory extends ContentfulModel
    {
        /**
         * {@inheritdoc}
         */
        protected $table = 'territories';
    
        /**
         * {@inheritdoc}
         */
        protected $fillable = [
            'slug',
            'title',
        ];
    
        /**
         * Picture attribute accessor.
         *
         * @return \Distilleries\Contentful\Models\Asset|null
         */
        public function getPictureAttribute(): ?Asset
        {
            return isset($this->payload['picture']) ? $this->contentfulAsset($this->payload['picture']) : null;
        }
    }

    $router->post('/webhook/live', 'WebhookController@live');
    $router->post('/webhook/preview', 'WebhookController@preview');

    $router->group(['prefix' => 'preview', 'middleware' => 'use_preview'], function () use ($router) {
        //
    });

    'use_preview' => Distilleries\Contentful\Http\Middleware\UsePreview::class,