Laravel MongoDB 5.0: Major Release With Exciting New Features!
Rate this announcement
The PHP team is happy to announce that version 5.0 of the Laravel MongoDB integration is now available!
This is a major release that introduces breaking changes to align the MongoDB integration with the Laravel frameworkās conventions and behaviors, making it easy for developers to use MongoDB when they are already familiar with Eloquent.
- ID aliasing: We have introduced automatic aliasing of
id
to_id
in MongoDB. This eliminates the need for specifyingprotected $primaryKey = '_id'
in model classes, simplifying your code. Replace$model->_id
with$model->id
in your code. - Date handling enhancements: All
DateTimeInterface
objects, including Carbon, are now automatically converted to MongoDBāsUTCDateTime
for insert and update operations. Similarly, when retrieving data, MongoDBāsUTCDateTime
is automatically converted back into Carbon date with the default timezone. This change simplifies working with dates in MongoDB, reducing the need for custom Eloquent casts. - Results as objects: Query results from MongoDB will now be returned as
stdClass
objects instead of arrays. The object properties can now be accessed using$item->name
rather than$item['name']
. - Simplified model customization:
$collection
has been replaced by$table
for customizing the collection name in Eloquent models, aligning with Laravel convention. - Provider removals: Several MongoDB-specific service providers have been removed, including
Auth\PasswordResetServiceProvider
,MongoDBQueueServiceProvider
, andQueue\Failed\MongoFailedJobProvider
. These providers are no longer necessary, asMongoDB\Connection
is now fully compatible with Laravelās classes. - Connection and logging updates:
MongoDB\Laravel\Connection
has been replaced withMongoDB\Connection
, and the query logging now uses MongoDB Monitoring Events.
This library may be installed or upgraded with:
1 composer require mongodb/laravel-mongodb:^5.0
Documentation and other resources to get you started with Laravel and the MongoDB database are shared below:
Give it a try today and let us know what you think! Feedback on this release is welcome in the GitHub discussion, as we continue to improve and enhance the integration.
Top Comments in Forums
There are no comments on this article yet.