Explore Developer Center's New Chatbot! MongoDB AI Chatbot can be accessed at the top of your navigation to answer all your MongoDB questions.

MongoDB Developer
MongoDB
plus
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
MongoDBchevron-right

Laravel MongoDB 5.0: Major Release With Exciting New Features!

Rishabh Bisht1 min read ā€¢ Published Sep 13, 2024 ā€¢ Updated Sep 13, 2024
PHPMongoDB
Facebook Icontwitter iconlinkedin icon
Rate this announcement
star-empty
star-empty
star-empty
star-empty
star-empty
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.

Highlights

  • ID aliasing: We have introduced automatic aliasing of id to _id in MongoDB. This eliminates the need for specifying protected $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ā€™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.

Installation

This library may be installed or upgraded with:
1composer require mongodb/laravel-mongodb:^5.0
Refer to the upgrade guide to handle the breaking changes.

Resources

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.
Start the Conversation

Facebook Icontwitter iconlinkedin icon
Rate this announcement
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Quickstart

Aggregation Framework with Node.js 3.3.2 Tutorial


Oct 01, 2024 | 9 min read
Tutorial

Interact with MongoDB Atlas in an AWS Lambda Function Using C#


Jan 23, 2024 | 5 min read
Article

Structuring Data With Serde in Rust


Apr 23, 2024 | 5 min read
Quickstart

Change Streams & Triggers with Node.js Tutorial


Aug 24, 2023 | 17 min read
Table of Contents
  • Highlights