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

Introducing MongoDB 8.0, the fastest MongoDB ever!
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
Article

Using AWS Rekognition to Analyse and Tag Uploaded Images


Sep 11, 2024 | 1 min read
Quickstart

MongoDB Change Streams with Python


Sep 23, 2022 | 9 min read
Tutorial

Using MongoDB Atlas Triggers to Summarize Airbnb Reviews with OpenAI


Oct 31, 2023 | 4 min read
Article

Java 21: Unlocking the Power of the MongoDB Java Driver With Virtual Threads


Jan 31, 2024 | 2 min read
Table of Contents
  • Highlights