File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -38,15 +38,20 @@ testability.
3838
3939The {+odm-short+} provides the ``DB`` method ``table()`` to access a collection.
4040Chain methods to specify commands and any constraints. Then, chain
41- the ``get()`` method at the end to run the methods and retrieve the results.
41+ the ``get()`` method at the end to run the methods and retrieve the
42+ results. To retrieve only the first matching result, chain the
43+ ``first()`` method instead of the ``get()`` method. Starting in
44+ {+odm-long+} v5.0, the query builder returns results as ``stdClass`` objects.
45+
4246The following example shows the syntax of a query builder call:
4347
4448.. code-block:: php
4549
4650 DB::table('<collection name>')
4751 // chain methods by using the "->" object operator
4852 ->get();
49- .. tip::
53+
54+ .. tip:: Set Database Connection
5055
5156 Before using the ``DB::table()`` method, ensure that you specify MongoDB as your application's
5257 default database connection. For instructions on setting the database connection,
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ Upgrade Library Version
1414.. contents:: On this page
1515 :local:
1616 :backlinks: none
17- :depth: 1
17+ :depth: 2
1818 :class: singlecol
1919
2020Overview
@@ -71,6 +71,26 @@ Version 5.x Breaking Changes
7171
7272This library version introduces the following breaking changes:
7373
74+ - The query builder returns results as as ``stdClass`` objects instead
75+ of as arrays. This change requires that you change array access to
76+ property access when interacting with query results.
77+
78+ The following code shows how to retrieve a query result and access a
79+ property from the result object in older versions compared to v5.0:
80+
81+ .. code-block:: php
82+ :emphasize-lines: 8-9
83+
84+ $document = DB::table('accounts')
85+ ->where('name', 'Anita Charles')
86+ ->first();
87+
88+ // older versions
89+ $document['balance'];
90+
91+ // v5.0
92+ $document->balance;
93+
7494- Removes support for the following classes:
7595
7696 - ``MongoDB\Laravel\Auth\DatabaseTokenRepository``. Instead, use the default
You can’t perform that action at this time.
0 commit comments