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

Join us at AWS re:Invent 2024! Learn how to use MongoDB for AI use cases.
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

Procedure to Allow Non-Root Users to Stop/Start/Restart "mongod" Process


May 16, 2022 | 3 min read
Tutorial

Joining Collections in MongoDB with .NET Core and an Aggregation Pipeline


Feb 03, 2023 | 7 min read
Tutorial

How We Backfilled 2 Million Database Documents


May 09, 2022 | 7 min read
Quickstart

Working with Change Streams from Your Swift Application


Jan 25, 2023 | 4 min read
Table of Contents
  • Highlights