PHPackages                             tttptd/laravel-doctrine-odm - 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. tttptd/laravel-doctrine-odm

ActiveLibrary[Database &amp; ORM](/categories/database)

tttptd/laravel-doctrine-odm
===========================

Doctrine MongoDB ODM integration for Laravel

0.1.1(1mo ago)092MITPHPPHP ^8.2CI passing

Since May 16Pushed 1mo agoCompare

[ Source](https://github.com/tttptd/laravel-doctrine-odm)[ Packagist](https://packagist.org/packages/tttptd/laravel-doctrine-odm)[ Docs](https://github.com/tttptd/laravel-doctrine-odm)[ RSS](/packages/tttptd-laravel-doctrine-odm/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (18)Versions (3)Used By (0)

   title TTTPTD Laravel Doctrine ODM   description Laravel package for Doctrine MongoDB ODM integration.  TTTPTD Laravel Doctrine ODM
===========================

[](#tttptd-laravel-doctrine-odm)

[![Tests](https://github.com/tttptd/laravel-doctrine-odm/actions/workflows/tests.yml/badge.svg)](https://github.com/tttptd/laravel-doctrine-odm/actions/workflows/tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/548a760cb37c2e9cf10e0762cf9908bd53d3d1151c38337a98b7b9311f997475/68747470733a2f2f706f7365722e707567782e6f72672f7474747074642f6c61726176656c2d646f637472696e652d6f646d2f762f737461626c65)](https://packagist.org/packages/tttptd/laravel-doctrine-odm)[![PHP Version Require](https://camo.githubusercontent.com/3e8d4b8628f733f216506d7cb7bb95449c8d2379cd2383504e3212eb0556f3d1/68747470733a2f2f706f7365722e707567782e6f72672f7474747074642f6c61726176656c2d646f637472696e652d6f646d2f726571756972652f706870)](https://packagist.org/packages/tttptd/laravel-doctrine-odm)[![License](https://camo.githubusercontent.com/83fe78d5dca6a27ee12b874a38dd5c583006ddfa9151d0643c25e3925cf477ab/68747470733a2f2f706f7365722e707567782e6f72672f7474747074642f6c61726176656c2d646f637472696e652d6f646d2f6c6963656e7365)](https://packagist.org/packages/tttptd/laravel-doctrine-odm)

Laravel package for integrating [Doctrine MongoDB ODM](https://www.doctrine-project.org/projects/mongodb-odm.html) with Laravel applications.

This package started as a fork of [chefsplate/laravel-doctrine-odm](https://github.com/chefsplate/laravel-doctrine-odm). The original project has not been maintained for a long time, so the fork was adapted for current Laravel applications and used privately in production projects for about a year and a half before being published. It is now public to make that work reusable, but the API and documentation are still being shaped around real project usage.

Table of Contents
-----------------

[](#table-of-contents)

- [Background](#background)
- [What It Solves](#what-it-solves)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Document Path Registry](#document-path-registry)
- [Usage](#usage)
- [Artisan Commands](#artisan-commands)
- [Testing](#testing)
- [Local Package Development](#local-package-development)

Background
----------

[](#background)

This package is based on [chefsplate/laravel-doctrine-odm](https://github.com/chefsplate/laravel-doctrine-odm). Since the upstream package appeared to be abandoned and no longer tracked modern Laravel and Doctrine ODM versions, this fork evolved as a private, project-driven continuation. It has been used in real applications for roughly eighteen months before this public release.

What It Solves
--------------

[](#what-it-solves)

Laravel does not include first-party Doctrine MongoDB ODM integration. This package provides the Laravel bridge:

- registers Doctrine `DocumentManager` in the Laravel container;
- publishes a MongoDB ODM config file;
- configures attribute metadata mapping;
- configures Doctrine proxies and hydrators;
- registers Gedmo Timestampable and Sluggable listeners;
- exposes Doctrine ODM console commands through Artisan;
- provides a small `PersistenceManager` abstraction for application code.

The package registers `DocumentManager` and `PersistenceManager` as scoped services. This is intentional: Doctrine `DocumentManager` is stateful and keeps an identity map/unit of work. In Laravel requests and queue jobs, one manager per lifecycle is the correct boundary; a singleton would leak stale documents between queue jobs.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 12
- MongoDB PHP extension
- MongoDB server

Install the MongoDB extension before installing the package:

```
pecl install mongodb
```

Then enable it in your PHP configuration if your environment does not do that automatically.

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

[](#installation)

Install the package from Packagist:

```
composer require tttptd/laravel-doctrine-odm:^0.1.1
```

Laravel package discovery registers the service provider automatically:

```
Ys\LaravelOdm\DoctrineMongoDBServiceProvider::class
```

Publish the config:

```
php artisan vendor:publish --provider="Ys\LaravelOdm\DoctrineMongoDBServiceProvider"
```

This creates:

```
config/mongodb.php

```

Configuration
-------------

[](#configuration)

Minimal `.env` example:

```
DB_MONGO_SERVER=mongodb://localhost:27017
DB_MONGO_DATABASE=app

DOCTRINE_METADATA_CACHE=array
DOCTRINE_PROXY_AUTOGENERATE=2
```

Default document path:

```
'documents' => [
    base_path('app/Documents'),
],
```

For modular applications, configure all document roots explicitly:

```
'documents' => [
    base_path('app/Documents'),
    base_path('domain/Art'),
    base_path('domain/Commerce'),
],
```

If some directories must be skipped by the metadata driver, add `exclude_documents`:

```
'exclude_documents' => [
    base_path('domain/Art/tests'),
],
```

Proxy and hydrator files are generated into:

```
'proxies' => [
    'namespace' => 'Proxies',
    'path' => storage_path('mongo_proxies'),
],

'hydrators' => [
    'namespace' => 'Hydrators',
    'path' => storage_path('mongo_hydrators'),
],
```

For production, disable automatic proxy generation and generate proxies during deploy:

```
DOCTRINE_PROXY_AUTOGENERATE=2
```

`2` means `Configuration::AUTOGENERATE_FILE_NOT_EXISTS`. The package also supports `3`, `Configuration::AUTOGENERATE_EVAL`, which is useful only for development.

Document Path Registry
----------------------

[](#document-path-registry)

`Ys\LaravelOdm\ODM\DocumentPathRegistry` is the public extension point for ODM document paths owned by Laravel packages.

The host `config/mongodb.php` should describe only host-owned documents:

```
'documents' => [
    base_path('app/Documents'),
    base_path('bbs'),
],
```

Reusable packages should not require the host application to hardcode `vendor//...` paths. Instead, a package service provider can add its document root through the registry:

```
use Ys\LaravelOdm\ODM\DocumentPathRegistry;

$this->callAfterResolving(
    DocumentPathRegistry::class,
    static fn(DocumentPathRegistry $registry) =>
        $registry->addDocumentPath(__DIR__ . '/../Domain/Entities'),
);
```

The registry is seeded from `mongodb.paths.documents` and `mongodb.paths.exclude_documents` first. Package providers append their own paths afterwards, so the metadata driver receives:

```
host config paths + package registered paths

```

`config/mongodb.php` does not overwrite package paths because it is only the initial source used to create the registry. The final Doctrine `AttributeDriver`is built from the registry after Laravel package providers have had a chance to register additional paths.

Usage
-----

[](#usage)

Inject Doctrine `DocumentManager` directly when you need full ODM APIs:

```
use Doctrine\ODM\MongoDB\DocumentManager;

final readonly class CreateArticleHandler
{
    public function __construct(
        private DocumentManager $documentManager,
    ) {
    }

    public function handle(Article $article): void
    {
        $this->documentManager->persist($article);
        $this->documentManager->flush();
    }
}
```

Or inject the package abstraction when application code only needs persistence operations:

```
use Ys\LaravelOdm\ODM\PersistenceManager;

final readonly class CreateArticleHandler
{
    public function __construct(
        private PersistenceManager $persistenceManager,
    ) {
    }

    public function handle(Article $article): void
    {
        $this->persistenceManager->persist($article);
        $this->persistenceManager->flush();
    }
}
```

Example document:

```
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[ODM\Document(collection: 'articles')]
final class Article
{
    #[ODM\Id]
    private ?string $id = null;

    #[ODM\Field(type: 'string')]
    private string $title;
}
```

Artisan Commands
----------------

[](#artisan-commands)

The package wraps common Doctrine ODM console commands as Artisan commands:

```
php artisan odm:generate:proxies
php artisan odm:generate:hydrators
php artisan odm:query
php artisan odm:clear-cache:metadata
php artisan odm:schema:create
php artisan odm:schema:drop
php artisan odm:schema:update
php artisan odm:schema:shard
```

Run Artisan list in your application to see the exact command signatures:

```
php artisan list odm
```

Testing
-------

[](#testing)

Install development dependencies:

```
composer install
```

Run the test suite:

```
composer test
```

The package uses PHPUnit 11 and Orchestra Testbench. The current tests cover:

- Laravel service provider registration;
- config publishing path;
- `DocumentManagerFactory` singleton lifetime;
- scoped `DocumentManager` lifecycle;
- `PersistenceManager` binding to the current scoped `DocumentManager`;
- Doctrine metadata loading from configured document paths;
- cache adapter creation;
- `PersistenceManagerDoctrine` delegation to Doctrine ODM.

The integration tests do not require a running MongoDB server. They verify container/config/metadata behavior without opening a database connection.

Local Package Development
-------------------------

[](#local-package-development)

For active development inside a Laravel application, clone this package next to the application:

```
~/example/laravel-doctrine-odm

```

In the application `composer.json`, temporarily add a path repository before installing/updating the package:

```
{
  "repositories": [
    {
      "type": "path",
      "url": "/Users/user/example/laravel-doctrine-odm",
      "options": {
        "symlink": true
      }
    }
  ]
}
```

Then update only this dependency:

```
composer update tttptd/laravel-doctrine-odm -W
```

With `symlink: true`, changes in the package checkout are immediately visible in the Laravel application.

Before committing application changes meant for CI/production, make sure `composer.lock` does not lock the package to a local `path` repository unless that is intentional. Public projects should normally resolve this package from Packagist.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance91

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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

Total

2

Last Release

43d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c867f09d1b4140feab970b17bd5e31bddac85579b1539720f1f325549c751cd?d=identicon)[tttptd](/maintainers/tttptd)

---

Tags

laraveldoctrineodmmongodbDoctrine ODM

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tttptd-laravel-doctrine-odm/health.svg)

```
[![Health](https://phpackages.com/badges/tttptd-laravel-doctrine-odm/health.svg)](https://phpackages.com/packages/tttptd-laravel-doctrine-odm)
```

###  Alternatives

[oro/platform

Business Application Platform (BAP)

645143.5k116](/packages/oro-platform)[leantime/leantime

Open source project management system for non-project managers. Simple like Trello, powerful like Jira. Built with neurodiversity in mind.

10.2k4.0k](/packages/leantime-leantime)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[concrete5/core

Concrete core subtree split

20166.1k53](/packages/concrete5-core)[open-dxp/opendxp

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

9421.6k64](/packages/open-dxp-opendxp)[chameleon-system/chameleon-base

The Chameleon System core.

1028.7k5](/packages/chameleon-system-chameleon-base)

PHPackages © 2026

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