Skip to content

Commit 3c70241

Browse files
authored
Merge branch '5.0' into merge-4.8-into-5.0-1732313336127
2 parents 3971a24 + c9b74e8 commit 3c70241

File tree

85 files changed

+1281
-1306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1281
-1306
lines changed

.github/PULL_REQUEST_TEMPLATE.md

-1
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/merge-up.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Merge up
33
on:
44
push:
55
branches:
6-
- "[0-9]+.[0-9]+"
6+
- "[0-9]+.[0-9x]+"
77

88
env:
99
GH_TOKEN: ${{ secrets.MERGE_UP_TOKEN }}
@@ -28,4 +28,5 @@ jobs:
2828
with:
2929
ref: ${{ github.ref_name }}
3030
branchNamePattern: '<major>.<minor>'
31+
devBranchNamePattern: '<major>.x'
3132
enableAutoMerge: true

.github/workflows/static-analysis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
php:
2424
- '8.1'
2525
- '8.2'
26+
- '8.3'
2627
steps:
2728
- name: Checkout
2829
uses: actions/checkout@v4

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [5.0.2] - 2024-09-17
5+
6+
* Fix missing return types in CommandSubscriber by @GromNaN in [#3158](https://github.com/mongodb/laravel-mongodb/pull/3158)
7+
8+
## [5.0.1] - 2024-09-13
9+
10+
* Restore support for Laravel 10 by @GromNaN in [#3148](https://github.com/mongodb/laravel-mongodb/pull/3148)
11+
12+
## [5.0.0] - 2024-09-12
13+
14+
* **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)
15+
* **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)
16+
* **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)
17+
* Remove `MongoFailedJobProvider`, replaced by Laravel `DatabaseFailedJobProvider` by @GromNaN in [#3122](https://github.com/mongodb/laravel-mongodb/pull/3122)
18+
* Remove custom `PasswordResetServiceProvider`, use the default `DatabaseTokenRepository` by @GromNaN in [#3124](https://github.com/mongodb/laravel-mongodb/pull/3124)
19+
* Remove `Blueprint::background()` method by @GromNaN in [#3132](https://github.com/mongodb/laravel-mongodb/pull/3132)
20+
* Replace `Collection` proxy class with Driver monitoring by @GromNaN in [#3137]((https://github.com/mongodb/laravel-mongodb/pull/3137)
21+
* Support options in `count()` queries by @verduck in [#3142](https://github.com/mongodb/laravel-mongodb/pull/3142)
22+
423
## [4.8.0] - 2024-08-27
524

625
* Add `Query\Builder::incrementEach()` and `decrementEach()` methods by @SmallRuralDog in [#2550](https://github.com/mongodb/laravel-mongodb/pull/2550)

composer.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"illuminate/database": "^10.30|^11",
3131
"illuminate/events": "^10.0|^11",
3232
"illuminate/support": "^10.0|^11",
33-
"mongodb/mongodb": "^1.15"
33+
"mongodb/mongodb": "^1.18"
3434
},
3535
"require-dev": {
3636
"mongodb/builder": "^0.2",
@@ -41,7 +41,8 @@
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"
44+
"phpstan/phpstan": "^1.10",
45+
"rector/rector": "^1.2"
4546
},
4647
"conflict": {
4748
"illuminate/bus": "< 10.37.2"
@@ -68,7 +69,6 @@
6869
"laravel": {
6970
"providers": [
7071
"MongoDB\\Laravel\\MongoDBServiceProvider",
71-
"MongoDB\\Laravel\\MongoDBQueueServiceProvider",
7272
"MongoDB\\Laravel\\MongoDBBusServiceProvider"
7373
]
7474
}
@@ -77,7 +77,8 @@
7777
"test": "phpunit",
7878
"test:coverage": "phpunit --coverage-clover ./coverage.xml",
7979
"cs": "phpcs",
80-
"cs:fix": "phpcbf"
80+
"cs:fix": "phpcbf",
81+
"rector": "rector"
8182
},
8283
"config": {
8384
"allow-plugins": {

docs/compatibility.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Compatibility
1515
:class: singlecol
1616

1717
.. meta::
18-
:keywords: laravel 9, laravel 10, laravel 11, 4.0, 4.1, 4.2
18+
:keywords: laravel 9, laravel 10, laravel 11, 4.0, 4.1, 4.2, 5.0
1919

2020
Laravel Compatibility
2121
---------------------

docs/eloquent-models/model-class.txt

+11-8
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ model attribute, stored in MongoDB as a :php:`MongoDB\\BSON\\UTCDateTime
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 :php:`DateTime <class.datetime>`
220-
or the `Carbon class <https://carbon.nesbot.com/docs/>`__ to work with dates
219+
This conversion lets you use the PHP :php:`DateTime
220+
<class.datetime>` 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/auth/PersonalAccessToken.php

-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ class PersonalAccessToken extends SanctumToken
1111

1212
protected $connection = 'mongodb';
1313
protected $table = 'personal_access_tokens';
14-
protected $primaryKey = '_id';
1514
protected $keyType = 'string';
1615
}

docs/includes/eloquent-models/PlanetThirdParty.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ class Planet extends CelestialBody
1010
use DocumentModel;
1111

1212
protected $fillable = ['name', 'diameter'];
13-
protected $primaryKey = '_id';
1413
protected $keyType = 'string';
1514
}

docs/includes/framework-compatibility-laravel.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- Laravel 10.x
88
- Laravel 9.x
99

10-
* - 4.2 to 4.8
10+
* - 4.2 to 5.0
1111
- ✓
1212
- ✓
1313
-

docs/includes/fundamentals/write-operations/WriteOperationsTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function testModelUpdateFluent(): void
162162

163163
// begin model update one fluent
164164
$concert = Concert::where(['performer' => 'Brad Mehldau'])
165-
->orderBy('_id')
165+
->orderBy('id')
166166
->first()
167167
->update(['venue' => 'Manchester Arena', 'ticketsSold' => 9543]);
168168
// end model update one fluent
@@ -370,31 +370,31 @@ public function testModelDeleteById(): void
370370

371371
$data = [
372372
[
373-
'_id' => 'CH-0401242000',
373+
'id' => 'CH-0401242000',
374374
'performer' => 'Mitsuko Uchida',
375375
'venue' => 'Carnegie Hall',
376376
'genres' => ['classical'],
377377
'ticketsSold' => 2121,
378378
'performanceDate' => new UTCDateTime(Carbon::create(2024, 4, 1, 20, 0, 0, 'EST')),
379379
],
380380
[
381-
'_id' => 'MSG-0212252000',
381+
'id' => 'MSG-0212252000',
382382
'performer' => 'Brad Mehldau',
383383
'venue' => 'Philharmonie de Paris',
384384
'genres' => [ 'jazz', 'post-bop' ],
385385
'ticketsSold' => 5745,
386386
'performanceDate' => new UTCDateTime(Carbon::create(2025, 2, 12, 20, 0, 0, 'CET')),
387387
],
388388
[
389-
'_id' => 'MSG-021222000',
389+
'id' => 'MSG-021222000',
390390
'performer' => 'Billy Joel',
391391
'venue' => 'Madison Square Garden',
392392
'genres' => [ 'rock', 'soft rock', 'pop rock' ],
393393
'ticketsSold' => 12852,
394394
'performanceDate' => new UTCDateTime(Carbon::create(2025, 2, 12, 20, 0, 0, 'CET')),
395395
],
396396
[
397-
'_id' => 'SF-06302000',
397+
'id' => 'SF-06302000',
398398
'performer' => 'The Rolling Stones',
399399
'venue' => 'Soldier Field',
400400
'genres' => [ 'rock', 'pop', 'blues' ],
@@ -478,22 +478,22 @@ public function testModelDeleteMultipleById(): void
478478
Concert::truncate();
479479
$data = [
480480
[
481-
'_id' => 3,
481+
'id' => 3,
482482
'performer' => 'Mitsuko Uchida',
483483
'venue' => 'Carnegie Hall',
484484
],
485485
[
486-
'_id' => 5,
486+
'id' => 5,
487487
'performer' => 'Brad Mehldau',
488488
'venue' => 'Philharmonie de Paris',
489489
],
490490
[
491-
'_id' => 7,
491+
'id' => 7,
492492
'performer' => 'Billy Joel',
493493
'venue' => 'Madison Square Garden',
494494
],
495495
[
496-
'_id' => 9,
496+
'id' => 9,
497497
'performer' => 'The Rolling Stones',
498498
'venue' => 'Soldier Field',
499499
],

docs/includes/query-builder/QueryBuilderTest.php

+22-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
namespace App\Http\Controllers;
66

7+
use Carbon\Carbon;
78
use Illuminate\Database\Query\Builder;
89
use Illuminate\Pagination\AbstractPaginator;
910
use Illuminate\Support\Facades\DB;
11+
use MongoDB\BSON\ObjectId;
1012
use MongoDB\BSON\Regex;
11-
use MongoDB\Laravel\Collection;
13+
use MongoDB\Collection;
1214
use MongoDB\Laravel\Tests\TestCase;
1315

1416
use function file_get_contents;
@@ -76,7 +78,7 @@ public function testOrWhere(): void
7678
// begin query orWhere
7779
$result = DB::connection('mongodb')
7880
->table('movies')
79-
->where('year', 1955)
81+
->where('id', new ObjectId('573a1398f29313caabce9682'))
8082
->orWhere('title', 'Back to the Future')
8183
->get();
8284
// end query orWhere
@@ -160,14 +162,26 @@ public function testWhereIn(): void
160162
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
161163
}
162164

165+
public function testWhereCarbon(): void
166+
{
167+
// begin query where date
168+
$result = DB::connection('mongodb')
169+
->table('movies')
170+
->where('released', Carbon::create(2010, 1, 15))
171+
->get();
172+
// end query where date
173+
174+
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
175+
}
176+
163177
public function testWhereDate(): void
164178
{
165-
// begin query whereDate
179+
// begin query whereDate string
166180
$result = DB::connection('mongodb')
167181
->table('movies')
168182
->whereDate('released', '2010-1-15')
169183
->get();
170-
// end query whereDate
184+
// end query whereDate string
171185

172186
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
173187
}
@@ -544,11 +558,11 @@ public function testUpsert(): void
544558

545559
$this->assertSame(2, $result);
546560

547-
$this->assertSame(119, DB::table('movies')->where('title', 'Inspector Maigret')->first()['runtime']);
548-
$this->assertSame(false, DB::table('movies')->where('title', 'Inspector Maigret')->first()['recommended']);
561+
$this->assertSame(119, DB::table('movies')->where('title', 'Inspector Maigret')->first()->runtime);
562+
$this->assertSame(false, DB::table('movies')->where('title', 'Inspector Maigret')->first()->recommended);
549563

550-
$this->assertSame(true, DB::table('movies')->where('title', 'Petit Maman')->first()['recommended']);
551-
$this->assertSame(72, DB::table('movies')->where('title', 'Petit Maman')->first()['runtime']);
564+
$this->assertSame(true, DB::table('movies')->where('title', 'Petit Maman')->first()->recommended);
565+
$this->assertSame(72, DB::table('movies')->where('title', 'Petit Maman')->first()->runtime);
552566
}
553567

554568
public function testUpdateUpsert(): void

docs/includes/usage-examples/DeleteOneTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testDeleteOne(): void
2727

2828
// begin-delete-one
2929
$deleted = Movie::where('title', 'Quiz Show')
30-
->orderBy('_id')
30+
->orderBy('id')
3131
->limit(1)
3232
->delete();
3333

docs/includes/usage-examples/FindManyTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testFindMany(): void
3535

3636
// begin-find
3737
$movies = Movie::where('runtime', '>', 900)
38-
->orderBy('_id')
38+
->orderBy('id')
3939
->get();
4040
// end-find
4141

docs/includes/usage-examples/FindOneTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public function testFindOne(): void
2424

2525
// begin-find-one
2626
$movie = Movie::where('directors', 'Rob Reiner')
27-
->orderBy('_id')
27+
->orderBy('id')
2828
->first();
2929

3030
echo $movie->toJson();
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"\]}$/');
34+
$this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
3535
}
3636
}

docs/includes/usage-examples/InsertOneTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public function testInsertOne(): void
3030
// end-insert-one
3131

3232
$this->assertInstanceOf(Movie::class, $movie);
33-
$this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","_id":"[a-z0-9]{24}"}$/');
33+
$this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","id":"[a-z0-9]{24}"}$/');
3434
}
3535
}

docs/includes/usage-examples/UpdateOneTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testUpdateOne(): void
3030

3131
// begin-update-one
3232
$updates = Movie::where('title', 'Carol')
33-
->orderBy('_id')
33+
->orderBy('id')
3434
->first()
3535
->update([
3636
'imdb' => [

docs/index.txt

+11-7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ Learn how to add the {+odm-short+} to a Laravel web application, connect to
5252
MongoDB hosted on MongoDB Atlas, and begin working with data in the
5353
:ref:`laravel-quick-start` section.
5454

55+
Upgrade Versions
56+
----------------
57+
58+
.. important::
59+
60+
{+odm-long+} v5.0 introduces breaking changes that might affect how you
61+
upgrade your application from a v4.x version.
62+
63+
Learn what changes you must make to your application to upgrade between
64+
major versions in the :ref:`laravel-upgrading` section.
65+
5566
Usage Examples
5667
--------------
5768

@@ -94,10 +105,3 @@ Compatibility
94105

95106
To learn more about which versions of {+odm-long+} and Laravel are
96107
compatible, see the :ref:`laravel-compatibility` section.
97-
98-
Upgrade Versions
99-
----------------
100-
101-
Learn what changes you must make to your application to upgrade versions in
102-
the :ref:`laravel-upgrading` section.
103-

0 commit comments

Comments
 (0)