PHPackages                             fuzzyma/contao-eloquent-bundle - 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. [Database &amp; ORM](/categories/database)
4. /
5. fuzzyma/contao-eloquent-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

fuzzyma/contao-eloquent-bundle
==============================

Creates possibility to use eloquents relations in your dca files

0.1.2(9y ago)0151MITPHPPHP ^5.5 | ^7.0

Since Jul 13Pushed 9y ago1 watchersCompare

[ Source](https://github.com/Fuzzyma/contao-eloquent-bundle)[ Packagist](https://packagist.org/packages/fuzzyma/contao-eloquent-bundle)[ RSS](/packages/fuzzyma-contao-eloquent-bundle/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (4)Used By (1)

ContaoEloquentBundle
====================

[](#contaoeloquentbundle)

This bundle depends on the great [eloquent-bundle](https://github.com/WouterJ/WouterJEloquentBundle) from wouterj which makes eloquent usable in symfony. We want to go a step further and integrate Eloquent in [Contao](https://contao.org/).

At the moment this bundle implements

- hasMany, hasOne, belongsTo, belongsToMany relations
- command to create dca-files for pivot tables
- Several Traits you may use in your models
- ContaoModelConsumerTrait (turns contao models into eloquent models)
- Eloquent models for all core Contao models

More features which will be implemented:

- hasManyThrough
- morphTo
- morphMany
- morphToMany
- morphedByMany

Guide
-----

[](#guide)

### 1. Install the Bundle

[](#1-install-the-bundle)

```
composer require fuzzyma/contao-eloquent-bundle
```

### 2. Activate the Bundle

[](#2-activate-the-bundle)

In your AppKernel.php add:

```
public function registerBundles() {

    $bundles = [

        //...
        new WouterJ\EloquentBundle\WouterJEloquentBundle(), // we depend on it so we have to load it
        new Fuzzyma\Contao\EloquentBundle\ContaoEloquentBundle() // and that's ours

    ];

}
```

This bundles are now active. But we have to configure the eloquent environment. You can see how it works here: [eloquent-bundle](https://github.com/WouterJ/WouterJEloquentBundle). But for simplification here is the short version:

### 3. Configure Eloquent

[](#3-configure-eloquent)

```
wouterj_eloquent:
    connections:
        default:
            database:  "%database_name%"
            driver:    mysql
            host:      "%database_host%"
            username:  "%database_user%"
            password:  "%database_password%"
            charset:   utf8
            collation: utf8_unicode_ci
            prefix:    'tl_'
    default_connection: default
    eloquent: true
    aliases: false
```

After this is done we can finally use it

Usage
-----

[](#usage)

Say we have a `Topic` model and a `Tag` model. Every `Topic` can have multiple `Tag`s and the other way round. To use Eloquents relation we need a pivot table but contao does not understand pivot tables. Furthermore we want a multiple select field for topics and tags which works just fine. We can do that:

```
/**
 * Table tl_topics
 */
$GLOBALS['TL_DCA']['tl_topics'] = array
(
    'config' => array
    (
        // all the config
        'model' => Fuzzyma\Contao\EloquentExampleProjectBundle\Models\Topic::class
    )
	// Fields
	'fields' => array
	(
         // id, tstamp and so on and:
        'tags' => array
        (
            'label' => &$GLOBALS['TL_LANG']['tl_topics']['tags'],
            'inputType' => 'select',
            'eval' => ['multiple' => true],
            'eloquent' => [
                'relation' => 'belongsToMany',
                'model' => Fuzzyma\Contao\EloquentExampleProjectBundle\Models\Tag::class,
                'label' => '%name% [%comment%]'
                // 'medthod' => 'tags' // is automatically assumed
            ]
        ),
	)
);
```

The important part is the model key in the config section and the eloquent key in the tags section. *Note:* Make sure, that the field-name is the same as defined in the Model. So your Topic Model would look like this:

```
namespace NamespaceToBundle\Models;

use Illuminate\Database\Eloquent\Model;
use Fuzzyma\Contao\EloquentBundle\Traits\ContaoFilesModelTrait; // only needed if you deal with files

class Topic extends Model
{

    use ContaoFilesModelTrait;

     // laravel use plural of class name as table. So in case you don't match the convention you can change it here
    protected $table = "topics";
    protected $guarded = [];
    public $timestamps = false; // we don't have timestamps but we could add them if we want

    // that method name must match the field name (without _id) or the specified method!!
    public function tags(){
        return $this->belongsToMany(Tag::class, 'tag_topic'); // you may want to name the pivot table here
    }

    // here the ContaoFilesModelTrait comes into place.
    // The Mutator will convert a call to $topic->thumbnail to a contao file model
    // of course that only works if you defined a field thumbnail in the dca
    public function getThumbnailAttribute($uuid){
        return $this->getContaoFile($uuid);
    }

    // same for setting a new file. Pass a FileModel, an UUID string or just binary
    public function setThumbnailAttribute($file){
        return $this->setContaoFile($file);
    }

}
```

For further code and other relations see the [contao-eloquent-example-project-bundle](https://github.com/Fuzzyma/contao-eloquent-example-project-bundle)

Generator
---------

[](#generator)

This bundle comes shipped with a command to create the dca file for you which then creates the pivot table. Just run the following command:

```
php app/console contao:make:pivot
```

For further options run

```
php app/console contao:make:pivot --help
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~14 days

Total

3

Last Release

3610d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3540542?v=4)[Ulrich-Matthias Schäfer](/maintainers/Fuzzyma)[@Fuzzyma](https://github.com/Fuzzyma)

---

Top Contributors

[![Fuzzyma](https://avatars.githubusercontent.com/u/3540542?v=4)](https://github.com/Fuzzyma "Fuzzyma (5 commits)")

### Embed Badge

![Health badge](/badges/fuzzyma-contao-eloquent-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/fuzzyma-contao-eloquent-bundle/health.svg)](https://phpackages.com/packages/fuzzyma-contao-eloquent-bundle)
```

###  Alternatives

[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19664.8M1.6k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6941.5M396](/packages/drupal-core-recommended)[contao/manager-bundle

Provides the Contao Managed Edition

181.3M68](/packages/contao-manager-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9317.2k55](/packages/open-dxp-opendxp)

PHPackages © 2026

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