sonata-project/doctrine-mongodb-admin-bundle
Symfony bundle that integrates Doctrine MongoDB ODM with SonataAdminBundle, providing admin services, mappers, and datagrid support to manage MongoDB documents via Sonata’s admin UI. Includes docs, CI, and versioned releases.
symfony/console, symfony/dependency-injection).jenssegers/mongodb or spatie/laravel-mongodb) that need a Sonata-like admin UI.symfony/dependency-injection to manage Sonata services in Laravel.SonataAdminBundle’s event system) rely on Symfony’s EventDispatcher, which would need Laravel Event listeners as a bridge.jenssegers/mongodb (Eloquent). A custom ModelManager would be needed to adapt ODM queries to Laravel’s MongoDB queries.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Symfony Dependency | Heavy reliance on Symfony components (DI, EventDispatcher, etc.). | Use Symfony Bridge Packages and Laravel’s Service Container for compatibility. |
| Doctrine ODM Gap | Laravel’s MongoDB drivers (jenssegers/mongodb) differ from Doctrine ODM. |
Create a custom ModelManager to translate Doctrine queries to Laravel MongoDB. |
| Template Engine | Sonata uses Twig; Laravel uses Blade. | Use Blade-Twig integration (e.g., blade-twig) or extract logic from templates. |
| Routing Conflicts | Sonata’s route generation may clash with Laravel’s. | Override route generation in a custom service or use Laravel’s router directly. |
| Performance Overhead | Sonata’s admin layer adds complexity (datagrid, filters, etc.). | Lazy-load components and optimize queries for MongoDB. |
| Maintenance Burden | Sonata is no longer actively maintained (last release: 2025-12-18). | Fork and maintain or use as a reference implementation for custom logic. |
spatie/laravel-admin with MongoDB support) that could reduce integration effort?| Laravel Component | Sonata Component | Integration Strategy |
|---|---|---|
| Service Container | Symfony DI | Use symfony/dependency-injection alongside Laravel’s container or wrap Sonata services in Laravel providers. |
| Routing | Sonata’s Router |
Override route generation or use Laravel’s router to handle Sonata admin routes. |
| Templating | Twig | Use Blade-Twig integration or extract logic from Sonata templates into Blade. |
| Authentication | Symfony Security | Map Sonata’s security checks to Laravel Gates/Policies. |
| ORM | Doctrine MongoDB ODM | Create a custom ModelManager to bridge Doctrine ODM queries to Laravel MongoDB. |
| Events | Symfony EventDispatcher | Use Laravel Events alongside Symfony’s dispatcher or translate events manually. |
| Forms | Sonata’s FormContractor |
Reuse form logic but render with Laravel Collective or Livewire. |
| Datagrid/Pagination | Sonata’s Datagrid |
Extract pagination logic and adapt to Laravel’s Illuminate\Pagination. |
Phase 1: Proof of Concept (PoC)
Phase 2: Service Provider Integration
DependencyInjection container.ModelManager, Datagrid, and Admin services.// app/Providers/SonataMongoDBAdminServiceProvider.php
public function register()
{
$this->app->register(SymfonyDependencyInjection::class);
$this->app->singleton(ModelManager::class, function ($app) {
return new CustomModelManager($app['mongodb']); // Laravel MongoDB
});
}
Phase 3: Template and View Layer
@extends('admin::base')
@section('content')
{{-- Use Sonata's logic via helper methods --}}
@php
$fieldDescription = app(SonataFieldDescriptionFactory::class)->create(...);
@endphp
{!! $fieldDescription->getType()->render($model) !!}
@endsection
Phase 4: Routing and Controllers
Route::get('/admin/posts', [SonataAdminController::class, 'list'])->name('admin.posts.list');
Phase 5: Authentication and Authorization
// app/Policies/SonataAdminPolicy.php
public function viewAny(User $user)
{
return $user->can('access_admin');
}
| Sonata Feature | Laravel Compatibility | Workaround |
|---|---|---|
| Datagrid (Filtering/Sorting) | Medium | Extract logic into custom query builder for Laravel MongoDB. |
| Batch Actions | High | Use Laravel’s queue system for async batch processing. |
| Embedded Document Support | Medium | Custom FieldDescription for nested MongoDB documents. |
| Event System |
How can I help you explore Laravel packages today?