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
Tutorial

Handle Time Series Data with MongoDB


Nov 19, 2024 | 13 min read
Article

How Prisma Introspects a Schema from a MongoDB Database


May 19, 2022 | 8 min read
Tutorial

Ensuring High Availability for MongoDB on Kubernetes


Jul 12, 2024 | 11 min read
Quickstart

Building Quarkus Application with MongoDB and Panache


Dec 03, 2024 | 5 min read
Table of Contents
  • Highlights