Skip to content

Commit f0b1b5c

Browse files
committed
Merge remote-tracking branch 'upstream/5.0' into DOCSP-43172-remove-databasetoken-class
2 parents 0af9fb3 + 2ee0dd9 commit f0b1b5c

40 files changed

+289
-584
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ This will help reviewers and should be a good start for the documentation.
77

88
- [ ] Add tests and ensure they pass
99
- [ ] Add an entry to the CHANGELOG.md file
10-
- [ ] Update documentation for new features

.github/workflows/build-ci.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ jobs:
2020
- "6.0"
2121
- "7.0"
2222
php:
23-
- "8.1"
2423
- "8.2"
2524
- "8.3"
2625
laravel:
27-
- "10.*"
2826
- "11.*"
27+
mode:
28+
- ""
2929
include:
30-
- php: "8.1"
31-
laravel: "10.*"
30+
- php: "8.2"
31+
laravel: "11.*"
3232
mongodb: "5.0"
3333
mode: "low-deps"
3434
os: "ubuntu-latest"
@@ -37,9 +37,6 @@ jobs:
3737
mongodb: "7.0"
3838
mode: "ignore-php-req"
3939
os: "ubuntu-latest"
40-
exclude:
41-
- php: "8.1"
42-
laravel: "11.*"
4340

4441
steps:
4542
- uses: "actions/checkout@v4"

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
strategy:
2222
matrix:
2323
php:
24-
- '8.1'
2524
- '8.2'
25+
- '8.3'
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ All notable changes to this project will be documented in this file.
33

44
## [5.0.0] - next
55

6-
* **BREAKING CHANGE** Use `id` as an alias for `_id` in commands and queries for compatibility with Eloquent packages by @GromNaN in [#3040](https://github.com/mongodb/laravel-mongodb/pull/3040)
6+
* Remove support for Laravel 10 by @GromNaN in [#3123](https://github.com/mongodb/laravel-mongodb/pull/3123)
7+
* **BREAKING CHANGE** Use `id` as an alias for `_id` in commands and queries for compatibility with Eloquent packages by @GromNaN in [#3040](https://github.com/mongodb/laravel-mongodb/pull/3040) and [#3136](https://github.com/mongodb/laravel-mongodb/pull/3136)
78
* **BREAKING CHANGE** Make Query\Builder return objects instead of array to match Laravel behavior by @GromNaN in [#3107](https://github.com/mongodb/laravel-mongodb/pull/3107)
9+
* **BREAKING CHANGE** In DB query results, convert BSON `UTCDateTime` objects into `Carbon` date with the default timezone by @GromNaN in [#3119](https://github.com/mongodb/laravel-mongodb/pull/3119)
10+
* Remove `MongoFailedJobProvider`, replaced by Laravel `DatabaseFailedJobProvider` by @GromNaN in [#3122](https://github.com/mongodb/laravel-mongodb/pull/3122)
11+
* Remove custom `PasswordResetServiceProvider`, use the default `DatabaseTokenRepository` by @GromNaN in [#3124](https://github.com/mongodb/laravel-mongodb/pull/3124)
12+
* Remove `Blueprint::background()` method by @GromNaN in [#3132](https://github.com/mongodb/laravel-mongodb/pull/3132)
13+
* Replace `Collection` proxy class with Driver monitoring by @GromNaN in [#3137]((https://github.com/mongodb/laravel-mongodb/pull/3137)
814

915
## [4.8.0] - 2024-08-27
1016

composer.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,27 @@
2222
],
2323
"license": "MIT",
2424
"require": {
25-
"php": "^8.1",
25+
"php": "^8.2",
2626
"ext-mongodb": "^1.15",
2727
"composer-runtime-api": "^2.0.0",
28-
"illuminate/cache": "^10.36|^11",
29-
"illuminate/container": "^10.0|^11",
30-
"illuminate/database": "^10.30|^11",
31-
"illuminate/events": "^10.0|^11",
32-
"illuminate/support": "^10.0|^11",
33-
"mongodb/mongodb": "^1.15"
28+
"illuminate/cache": "^11",
29+
"illuminate/container": "^11",
30+
"illuminate/database": "^11",
31+
"illuminate/events": "^11",
32+
"illuminate/support": "^11",
33+
"mongodb/mongodb": "^1.18"
3434
},
3535
"require-dev": {
3636
"mongodb/builder": "^0.2",
3737
"league/flysystem-gridfs": "^3.28",
3838
"league/flysystem-read-only": "^3.0",
39-
"phpunit/phpunit": "^10.3",
40-
"orchestra/testbench": "^8.0|^9.0",
39+
"phpunit/phpunit": "^10.5",
40+
"orchestra/testbench": "^9.0",
4141
"mockery/mockery": "^1.4.4",
4242
"doctrine/coding-standard": "12.0.x-dev",
4343
"spatie/laravel-query-builder": "^5.6",
44-
"phpstan/phpstan": "^1.10"
45-
},
46-
"conflict": {
47-
"illuminate/bus": "< 10.37.2"
44+
"phpstan/phpstan": "^1.10",
45+
"rector/rector": "^1.2"
4846
},
4947
"suggest": {
5048
"league/flysystem-gridfs": "Filesystem storage in MongoDB with GridFS",
@@ -68,7 +66,6 @@
6866
"laravel": {
6967
"providers": [
7068
"MongoDB\\Laravel\\MongoDBServiceProvider",
71-
"MongoDB\\Laravel\\MongoDBQueueServiceProvider",
7269
"MongoDB\\Laravel\\MongoDBBusServiceProvider"
7370
]
7471
}
@@ -77,7 +74,8 @@
7774
"test": "phpunit",
7875
"test:coverage": "phpunit --coverage-clover ./coverage.xml",
7976
"cs": "phpcs",
80-
"cs:fix": "phpcbf"
77+
"cs:fix": "phpcbf",
78+
"rector": "rector"
8179
},
8280
"config": {
8381
"allow-plugins": {

docs/eloquent-models/model-class.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ type, to the Laravel ``datetime`` type.
216216
To learn more, see `Attribute Casting <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-mutators#attribute-casting>`__
217217
in the Laravel documentation.
218218

219-
This conversion lets you use the PHP `DateTime <https://www.php.net/manual/en/class.datetime.php>`__
220-
or the `Carbon class <https://carbon.nesbot.com/docs/>`__ to work with dates
219+
This conversion lets you use the PHP `DateTime
220+
<https://www.php.net/manual/en/class.datetime.php>`__ class to work with dates
221221
in this field. The following example shows a Laravel query that uses the
222222
casting helper on the model to query for planets with a ``discovery_dt`` of
223223
less than three years ago:
@@ -226,6 +226,13 @@ less than three years ago:
226226

227227
Planet::where( 'discovery_dt', '>', new DateTime('-3 years'))->get();
228228

229+
.. note:: Carbon Date Class
230+
231+
Starting in {+odm-long+} v5.0, ``UTCDateTime`` BSON values in MongoDB
232+
are returned as `Carbon <https://carbon.nesbot.com/docs/>`__ date
233+
classes in query results. The {+odm-short+} applies the default
234+
timezone when performing this conversion.
235+
229236
To learn more about MongoDB's data types, see :manual:`BSON Types </reference/bson-types/>`
230237
in the Server manual.
231238

@@ -295,12 +302,8 @@ including this trait, you can make the third-party class compatible with
295302
MongoDB.
296303

297304
When you apply the ``DocumentModel`` trait to a model class, you must
298-
declare the following properties in your class:
299-
300-
- ``$primaryKey = '_id'``, because the ``_id`` field uniquely
301-
identifies MongoDB documents
302-
- ``$keyType = 'string'``, because the {+odm-short+} casts MongoDB
303-
``ObjectId`` values to type ``string``
305+
set the ``$keyType`` property to ``'string'`` as the {+odm-short+}
306+
casts MongoDB ``ObjectId`` values to type ``string``.
304307

305308
Extended Class Example
306309
~~~~~~~~~~~~~~~~~~~~~~

docs/includes/query-builder/QueryBuilderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
use Illuminate\Database\Query\Builder;
88
use Illuminate\Pagination\AbstractPaginator;
99
use Illuminate\Support\Facades\DB;
10+
use MongoDB\BSON\ObjectId;
1011
use MongoDB\BSON\Regex;
11-
use MongoDB\Laravel\Collection;
12+
use MongoDB\Collection;
1213
use MongoDB\Laravel\Tests\TestCase;
1314

1415
use function file_get_contents;
@@ -63,7 +64,7 @@ public function testOrWhere(): void
6364
// begin query orWhere
6465
$result = DB::connection('mongodb')
6566
->table('movies')
66-
->where('year', 1955)
67+
->where('id', new ObjectId('573a1398f29313caabce9682'))
6768
->orWhere('title', 'Back to the Future')
6869
->get();
6970
// end query orWhere

docs/includes/usage-examples/FindOneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public function testFindOne(): void
3131
// end-find-one
3232

3333
$this->assertInstanceOf(Movie::class, $movie);
34-
$this->expectOutputRegex('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
34+
$this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
3535
}
3636
}

docs/query-builder.txt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,28 @@ Logical OR Example
176176

177177
The following example shows how to chain the ``orWhere()``
178178
query builder method to retrieve documents from the
179-
``movies`` collection that either match the ``year``
180-
value of ``1955`` or match the ``title`` value ``"Back to the Future"``:
179+
``movies`` collection in which the value of the ``_id``
180+
field is ``ObjectId('573a1398f29313caabce9682')`` or
181+
the value of the ``title`` field is ``"Back to the Future"``:
181182

182183
.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
183184
:language: php
184185
:dedent:
185186
:start-after: begin query orWhere
186187
:end-before: end query orWhere
187188

189+
.. note::
190+
191+
You can use the ``id`` alias in your queries to represent the
192+
``_id`` field in MongoDB documents, as shown in the preceding
193+
code. When you run a find operation using the query builder, {+odm-short+}
194+
automatically converts between ``id`` and ``_id``. This provides better
195+
compatibility with Laravel, as the framework assumes that each record has a
196+
primary key named ``id`` by default.
197+
198+
Because of this behavior, you cannot have two separate ``id`` and ``_id``
199+
fields in your documents.
200+
188201
.. _laravel-query-builder-logical-and:
189202

190203
Logical AND Example
@@ -346,6 +359,13 @@ query builder method to retrieve documents from the
346359
:start-after: begin query whereDate
347360
:end-before: end query whereDate
348361

362+
.. note:: Date Query Result Type
363+
364+
Starting in {+odm-long+} v5.0, ``UTCDateTime`` BSON values in MongoDB
365+
are returned as `Carbon <https://carbon.nesbot.com/docs/>`__ date
366+
classes in query results. The {+odm-short+} applies the default
367+
timezone when performing this conversion.
368+
349369
.. _laravel-query-builder-pattern:
350370

351371
Text Pattern Match Example

docs/upgrade.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Overview
2222

2323
On this page, you can learn how to upgrade {+odm-long+} to a new major version.
2424
This page also includes the changes you must make to your application to upgrade
25-
your object-document mapper (ODM) version without losing functionality, if applicable.
25+
your version of the {+odm-short+} without losing functionality, if applicable.
2626

2727
How to Upgrade
2828
--------------
@@ -61,6 +61,9 @@ version releases that introduced them. When upgrading library versions,
6161
address all the breaking changes between your current version and the
6262
planned upgrade version.
6363

64+
- :ref:`laravel-breaking-changes-v5.x`
65+
- :ref:`laravel-breaking-changes-v4.x`
66+
6467
.. _laravel-breaking-changes-v5.x:
6568

6669
Version 5.x Breaking Changes
@@ -77,6 +80,14 @@ This library version introduces the following breaking changes:
7780
- ``MongoDB\Laravel\Queue\Failed\MongoFailedJobProvider``. Instead,
7881
use the default ``Illuminate\Queue\Failed\DatabaseFailedJobProvider``
7982
class and specify a connection to MongoDB.
83+
84+
- In query results, the library converts BSON ``UTCDateTime`` objects to ``Carbon``
85+
date classes, applying the default timezone.
86+
87+
- ``id`` is an alias for the ``_id`` field in MongoDB documents, and the library
88+
automatically converts between ``id`` and ``_id`` when querying data. Because
89+
of this behavior, you cannot have two separate ``id`` and ``_id`` fields in your
90+
documents.
8091

8192
.. _laravel-breaking-changes-v4.x:
8293

0 commit comments

Comments
 (0)