Complete Laravel Nova adapter for MongoDB - enables full Nova functionality on MongoDB databases without SQL dependencies
francescoprisco/nova-mongodb is a Laravel package for complete laravel nova adapter for mongodb - enables full nova functionality on mongodb databases without sql dependencies.
It currently has 1 GitHub stars and 0 downloads on Packagist (latest version 1.0.0).
Install it with composer require francescoprisco/nova-mongodb.
Discover more Laravel packages by francescoprisco
or browse all Laravel packages to compare alternatives.
Last updated
Complete package to integrate Laravel Nova with MongoDB, enabling all Nova features on MongoDB databases without any SQL dependencies.
composer require francescoprisco/nova-mongodb
The service provider is automatically registered via Laravel package auto-discovery.
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'];
}
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(),
];
}
}
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',
];
}
MongoDBResourceBase class for Nova resources with complete MongoDB support:
$regex)MongoDBConnectionExtends standard MongoDB connection to handle nested transactions:
ModelObserverAutomatic observer for action logging:
action_events collection with complete change trackingActionEvent: 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
MongoNotifiable: Complete notification management with notifications() and unreadNotifications() relations
HandlesMorphRelations: Helper for MongoDB polymorphic relations
The package automatically registers custom routes for Nova notifications:
GET /nova-api/nova-notifications - List notificationsPOST /nova-api/nova-notifications/{id}/read - Mark as readPOST /nova-api/nova-notifications/{id}/unread - Mark as unreadPOST /nova-api/nova-notifications/read-all - Mark all as readDELETE /nova-api/nova-notifications/{id} - Delete notificationDELETE /nova-api/nova-notifications - Delete allphp 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
}
In app/Providers/NovaServiceProvider.php:
use App\Nova\Product;
protected function resources()
{
Nova::resources([
Product::class,
// other resources...
]);
}
Laravel Scout advanced search requires a custom MongoDB driver. Currently search uses native MongoDB regex.
Cards/Metrics using complex SQL aggregations may require rewriting using MongoDB aggregation pipeline.
Nova Lenses using complex SQL queries may not work directly and require adaptation.
Verify that:
MongoDBResource$search fields are definedconnection = 'mongodb'Verify:
MongoDB\Laravel\Auth\UserMongoNotifiable traitconfig/auth.php points to the correct modelThe package automatically optimizes:
Roadmap:
MIT License - Francesco Prisco
For issues and support: [email protected]