francescoprisco/nova-mongodb 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

francescoprisco/nova-mongodb

Composer 安装命令:

composer require francescoprisco/nova-mongodb

包简介

Complete Laravel Nova adapter for MongoDB - enables full Nova functionality on MongoDB databases without SQL dependencies

README 文档

README

Complete package to integrate Laravel Nova with MongoDB, enabling all Nova features on MongoDB databases without any SQL dependencies.

✨ Features

  • Nova Resources: Complete CRUD on MongoDB collections
  • Full-Text Search: Case-insensitive regex search on MongoDB
  • Action Events: Complete action logging system via Observer pattern
  • Authentication: User model fully on MongoDB
  • Notifications: Complete notification system with mark read/unread on MongoDB
  • Transaction Handling: Automatic nested transaction management
  • Zero SQL: No SQL database dependencies

📦 Installation

composer require francescoprisco/nova-mongodb

The service provider is automatically registered via Laravel package auto-discovery.

MongoDB Configuration

Make sure you have MongoDB connection configured in your config/database.php:

'connections' => [
    'mongodb' => [
        'driver' => 'mongodb',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', 27017),
        'database' => env('DB_DATABASE', 'database'),
        'username' => env('DB_USERNAME', ''),
        'password' => env('DB_PASSWORD', ''),
        'options' => [
            'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'),
        ],
    ],
],

## ⚙️ Configuration

### 1. User Model

```php
use MongoDB\Laravel\Auth\User as Authenticatable;
use FrancescoPrisco\NovaMongoDB\Traits\MongoNotifiable;

class User extends Authenticatable
{
    use MongoNotifiable;
    
    protected $connection = 'mongodb';
    protected $collection = 'users';
    
    protected $fillable = ['name', 'email', 'password'];
}

2. Nova Resources

Resources must extend MongoDBResource:

use FrancescoPrisco\NovaMongoDB\MongoDBResource;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\Select;

class Bookings extends MongoDBResource
{
    public static $model = \App\Models\Bookings::class;
    public static $title = 'customer_name';
    public static $search = ['id', 'customer_name', 'status'];
    
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('Customer Name')->sortable(),
            DateTime::make('Booking Date')->sortable(),
            Select::make('Status')->options([
                'pending' => 'Pending',
                'confirmed' => 'Confirmed',
                'cancelled' => 'Cancelled',
            ]),
            Text::make('Notes')->hideFromIndex(),
        ];
    }
}

3. MongoDB Models

use MongoDB\Laravel\Eloquent\Model;

class Bookings extends Model
{
    protected $connection = 'mongodb';
    protected $collection = 'bookings';
    
    protected $fillable = [
        'customer_name',
        'booking_date',
        'status',
        'notes',
    ];
    
    protected $casts = [
        'booking_date' => 'datetime',
    ];
}

🏗️ Architecture

Main Components

MongoDBResource

Base class for Nova resources with complete MongoDB support:

  • Case-insensitive regex search via MongoDB ($regex)
  • Correct type hints for MongoDB builder
  • Compatibility with all Nova CRUD operations

MongoDBConnection

Extends standard MongoDB connection to handle nested transactions:

  • Automatically catches errors from transactions already in progress
  • Executes callbacks directly when necessary
  • Prevents "Transaction already in progress" errors

ModelObserver

Automatic observer for action logging:

  • Automatically registered on all MongoDB models
  • Logs created, updated, deleted events
  • Saves to action_events collection with complete change tracking

MongoDB Models

ActionEvent: Saves action events in action_events collection with complete details (batch_id, user_id, changes, original, status) NovaNotification: Notification model in notifications collection with read/unread support

Traits

MongoNotifiable: Complete notification management with notifications() and unreadNotifications() relations HandlesMorphRelations: Helper for MongoDB polymorphic relations

Custom Routes

The package automatically registers custom routes for Nova notifications:

  • GET /nova-api/nova-notifications - List notifications
  • POST /nova-api/nova-notifications/{id}/read - Mark as read
  • POST /nova-api/nova-notifications/{id}/unread - Mark as unread
  • POST /nova-api/nova-notifications/read-all - Mark all as read
  • DELETE /nova-api/nova-notifications/{id} - Delete notification
  • DELETE /nova-api/nova-notifications - Delete all

🚀 Usage

Create a new resource

php artisan nova:resource Product

Modify the generated resource:

use FrancescoPrisco\NovaMongoDB\MongoDBResource;

class Product extends MongoDBResource
{
    public static $model = \App\Models\Product::class;
    public static $search = ['name', 'sku', 'description'];
    
    // ... fields and configuration
}

Register the resource

In app/Providers/NovaServiceProvider.php:

use App\Nova\Product;

protected function resources()
{
    Nova::resources([
        Product::class,
        // other resources...
    ]);
}

⚠️ Known Limitations

1. Scout Search

Laravel Scout advanced search requires a custom MongoDB driver. Currently search uses native MongoDB regex.

2. Advanced Metrics

Cards/Metrics using complex SQL aggregations may require rewriting using MongoDB aggregation pipeline.

3. Lenses

Nova Lenses using complex SQL queries may not work directly and require adaptation.

🔧 Troubleshooting

Search not working

Verify that:

  1. The resource extends MongoDBResource
  2. The $search fields are defined
  3. The model uses connection = 'mongodb'

User cannot authenticate

Verify:

  1. User model extends MongoDB\Laravel\Auth\User
  2. Uses the MongoNotifiable trait
  3. config/auth.php points to the correct model

📊 Performance

The package automatically optimizes:

  • Multiple queries via eager loading
  • Automatic indexing of search fields
  • Nova-compatible result caching

🛠️ Future Development

Roadmap:

  • Resource viewer to display ActionEvents in Nova UI
  • Advanced metrics/cards adapter with aggregation pipeline
  • Scout driver for MongoDB full-text search
  • Support for custom Lenses
  • Complete test suite
  • MongoDB-native dashboard widgets with real-time updates

📋 Requirements

  • PHP 8.2+
  • Laravel 11.0+ or 12.0+
  • Laravel Nova 5.0+
  • MongoDB 5.0+
  • mongodb/laravel-mongodb ^5.5

📄 License

MIT License - Francesco Prisco

🤝 Support

For issues and support: francesco.prisco@generazioneai.it

francescoprisco/nova-mongodb 适用场景与选型建议

francescoprisco/nova-mongodb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nosql」 「database」 「mongodb」 「adapter」 「nova」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 francescoprisco/nova-mongodb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 francescoprisco/nova-mongodb 我们能提供哪些服务?
定制开发 / 二次开发

基于 francescoprisco/nova-mongodb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 35
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-19