Laravel MongoDB releases version 5.0

Version 5.0 of the official Laravel MongoDB integration is now available. This major update introduces breaking changes to better align the MongoDB integration with Laravel’s conventions and behaviors, simplifying MongoDB usage for developers already familiar with Eloquent.

What’s New

  • ID aliasing: Automatic aliasing of id to _id in MongoDB is now supported, eliminating the need for specifying protected $primaryKey = '_id' in model classes, simplifying the code. Replace $model->_id with $model->id in your code.
  • Date handling enhancements: All DateTimeInterface objects, including Carbon, are now automatically converted to MongoDB’s UTCDateTime for insert and update operations. Similarly, when retrieving data, MongoDB’s UTCDateTime 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, and Queue\Failed\MongoFailedJobProvider. These providers are no longer necessary, as MongoDB\Connection is now fully compatible with Laravel’s classes.
  • Connection and logging updates: MongoDB\Laravel\Connection has been replaced with MongoDB\Connection, and the query logging now uses MongoDB Monitoring Events.

Refer to the upgrade guide to handle the breaking changes.

Resources


The post Laravel MongoDB releases version 5.0 appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

Read more

© 2024 Extly, CB - All rights reserved.