Skip to content

Commit 979cf52

Browse files
GromNaNalcaeusrustagir
authored
PHPORM-219 Deprecate Connection::collection() and Schema::collection() (#3062)
Use `table()` method instead, consistent with Laravel. Co-authored-by: Andreas Braun <git@alcaeus.org> Co-authored-by: Rea Rustagi <85902999+rustagir@users.noreply.github.com>
1 parent 4f2a8df commit 979cf52

16 files changed

+375
-355
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44
## [4.8.0] - next
55

66
* Add `Query\Builder::incrementEach()` and `decrementEach()` methods by @SmallRuralDog in [#2550](https://github.com/mongodb/laravel-mongodb/pull/2550)
7+
* Deprecate `Connection::collection()` and `Schema\Builder::collection()` methods by @GromNaN in [#3062](https://github.com/mongodb/laravel-mongodb/pull/3062)
78

89
## [4.7.0] - 2024-07-19
910

docs/fundamentals/database-collection.txt

+12-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ create a database connection to the ``animals`` database in the
5656

5757
.. code-block:: php
5858
:emphasize-lines: 1,8
59-
59+
6060
'default' => 'mongodb',
6161

6262
'connections' => [
@@ -77,7 +77,7 @@ The following example shows how to specify multiple database connections
7777
``plants`` databases:
7878

7979
.. code-block:: php
80-
80+
8181
'connections' => [
8282

8383
'mongodb' => [
@@ -145,23 +145,29 @@ Laravel retrieves results from the ``flowers`` collection:
145145

146146
Flower::where('name', 'Water Lily')->get()
147147

148+
.. note::
149+
150+
Starting in {+odm-short+} v4.8, the ``DB::collection()`` method
151+
is deprecated. As shown in the following example, you can use the ``DB::table()``
152+
method to access a MongoDB collection.
153+
148154
If you are unable to accomplish your operation by using an Eloquent
149-
model, you can access the query builder by calling the ``collection()``
155+
model, you can access the query builder by calling the ``table()``
150156
method on the ``DB`` facade. The following example shows the same query
151157
as in the preceding example, but the query is constructed by using the
152-
``DB::collection()`` method:
158+
``DB::table()`` method:
153159

154160
.. code-block:: php
155161

156162
DB::connection('mongodb')
157-
->collection('flowers')
163+
->table('flowers')
158164
->where('name', 'Water Lily')
159165
->get()
160166

161167
List Collections
162168
----------------
163169

164-
To see information about each of the collections in a database, call the
170+
To see information about each of the collections in a database, call the
165171
``listCollections()`` method.
166172

167173
The following example accesses a database connection, then

0 commit comments

Comments
 (0)