PHPackages                             distilleries/contentful - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. distilleries/contentful

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

distilleries/contentful
=======================

Package to use Contentful in offline mode.

2.3.1(6y ago)27102[2 issues](https://github.com/Distilleries/Laravel-Contentful-Utilities/issues)MITPHPPHP &gt;=7.1.3

Since Jun 21Pushed 6y ago2 watchersCompare

[ Source](https://github.com/Distilleries/Laravel-Contentful-Utilities)[ Packagist](https://packagist.org/packages/distilleries/contentful)[ RSS](/packages/distilleries-contentful/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (11)Versions (14)Used By (0)

[![Build Status](https://camo.githubusercontent.com/46ca7ee69f167b049cc10821a5862c9facd793e2838539445d8b06370944fc6d/68747470733a2f2f7472617669732d63692e6f72672f44697374696c6c65726965732f4c61726176656c2d436f6e74656e7466756c2d5574696c69746965732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Distilleries/Laravel-Contentful-Utilities)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/de1a90b82b020531615b6088703eca4d5a6899eedd206f82476b554ccf00843b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f44697374696c6c65726965732f4c61726176656c2d436f6e74656e7466756c2d5574696c69746965732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Distilleries/Laravel-Contentful-Utilities/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/1dfc00cc362d29976f7f24bff6cbe1c1384754933d17af56efa63281f0068151/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f44697374696c6c65726965732f4c61726176656c2d436f6e74656e7466756c2d5574696c69746965732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Distilleries/Laravel-Contentful-Utilities/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/4eb4a286dc137b60548478d6778981fa970a57970a176fd41ef7d6b9616084ce/68747470733a2f2f706f7365722e707567782e6f72672f64697374696c6c65726965732f636f6e74656e7466756c2f646f776e6c6f616473)](https://packagist.org/packages/distilleries/contentful)[![Latest Stable Version](https://camo.githubusercontent.com/4ca1b6f03da7fc995fd50c8e39bd339df241cd3b03480f05b738d0ed3f05c338/68747470733a2f2f706f7365722e707567782e6f72672f64697374696c6c65726965732f636f6e74656e7466756c2f76657273696f6e)](https://packagist.org/packages/distilleries/contentful)[![License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE)

Distilleries / Laravel-Contentful-Utilities
===========================================

[](#distilleries--laravel-contentful-utilities)

Laravel-Contentful-Utilities is a Laravel 5.6 - 5.8 / Lumen package 5.6 - 5.8 package to use [contentful](https://www.contentful.com/) in offline mode with and without preview. Contentful is a headless CMS in cloud you can have more information on their website

Features
--------

[](#features)

- Model generator from contentful
- Migration generator from contentful
- Synchronization from contentful to database

Installation
------------

[](#installation)

### Composer

[](#composer)

Install the \[composer package\] by running the following command:

`composer require distilleries/contentful`

Models and Mapper
-----------------

[](#models-and-mapper)

When we synchronize all the data on database the mapper link to the model are call. This mapper car provide the extract of field you would like one the database. For example you want to externalize the title and the slug on the database you have to change the migration generated and the mapper.

```
    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;
        }
    }
```

All the model generated have a getters for all the payload fields. If you want to externalize the field on database.

Command-line tools
------------------

[](#command-line-tools)

To make model and mapper from contentful

- `php artisan contentful:generate-models`

ℹ️ Models are generated on app\_path('Models'); and the mappers are generated on app\_path('Models/Mappers');

To make migration from contentful model

- `php artisan contentful:generate-migrations`

To launch the synchronisation you can use this command line

- `php artisan contentful:sync-data  {--preview}`
- `php artisan contentful:sync-flatten  {--preview}`

ℹ️ --preview is optional and use if you want to flatten the preview database.

CommandExplainsync-dataGet all the entries from contentful and put in the flatten databasesync-flattenGet all the entries from data table to explode on all the other typesWebhook
-------

[](#webhook)

To flatten the preview or the regular database you need to set the webhook on Contentful

Create a controller and use the trait:

`use \Distilleries\Contentful\Http\Controllers\WebhookTrait;`

Make the route callable in post:

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

- Live method is called to save on live mode
- Preview method is called to save the preview data

To display the site with preview database you have to use UsePreview middleware.

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

Add your middleware:

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Recently: every ~23 days

Total

12

Last Release

2429d ago

Major Versions

1.0.0 → 2.0.02018-09-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/c1edc17683ed39a2cc6dbe453c2c5aaa63468fc5b54f13941f260ebe260da211?d=identicon)[Kezho](/maintainers/Kezho)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/distilleries-contentful/health.svg)

```
[![Health](https://phpackages.com/badges/distilleries-contentful/health.svg)](https://phpackages.com/packages/distilleries-contentful)
```

###  Alternatives

[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
