11.. _laravel-upgrading:
22
3- =========
4- Upgrading
5- =========
3+ =======================
4+ Upgrade Library Version
5+ =======================
66
77.. facet::
88 :name: genre
@@ -11,39 +11,109 @@ Upgrading
1111.. meta::
1212 :keywords: php framework, odm, code example
1313
14- The PHP library uses `semantic versioning <https://semver.org/>`__. Upgrading
15- to a new major version may require changes to your application.
14+ .. contents:: On this page
15+ :local:
16+ :backlinks: none
17+ :depth: 1
18+ :class: singlecol
1619
17- Upgrading from version 3 to 4
18- -----------------------------
20+ Overview
21+ --------
1922
20- - Laravel 10.x is required
23+ On this page, you can learn how to upgrade {+odm-short+} to a new major version.
24+ 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.
2126
22- - Change dependency name in your composer.json to ``"mongodb/laravel-mongodb": "^4.0"``
23- and run ``composer update``
27+ How to Upgrade
28+ --------------
2429
25- - Change namespace from ``Jenssegers\Mongodb\`` to ``MongoDB\Laravel\``
26- in your models and config
30+ Before you upgrade, perform the following actions:
2731
28- - Remove support for non-Laravel projects
32+ - Ensure the new library version is compatible with the MongoDB Server version
33+ your application connects to and the version of Laravel that your
34+ application runs on. See the :ref:`<laravel-compatibility>`
35+ page for this information.
36+ - Address any breaking changes between the version of {+odm-short+} that
37+ your application currently uses and your planned upgrade version in the
38+ :ref:`<laravel-breaking-changes>` section of this guide.
2939
30- - Replace ``$dates`` with ``$casts`` in your models
40+ To upgrade your library version, run the following command in your application's
41+ directory:
3142
32- - Call ``$model->save()`` after ``$model->unset('field')`` to persist the change
43+ .. code-block:: bash
44+
45+ composer require mongodb/laravel-mongodb:{+package-version+}
3346
34- - Replace calls to ``Query\Builder::whereAll($column, $values)`` with
35- ``Query\Builder::where($column, 'all', $values)``
47+ To upgrade to a different version of the library, replace the information after
48+ ``laravel-mongodb:`` with your preferred version number.
3649
37- - ``Query\Builder::delete()`` doesn't accept ``limit()`` other than ``1`` or ``null``.
50+ .. _laravel-breaking-changes:
3851
39- - ``whereDate``, ``whereDay``, ``whereMonth``, ``whereYear``, ``whereTime``
40- now use MongoDB operators on date fields
52+ Breaking Changes
53+ ----------------
4154
42- - Replace ``Illuminate\Database\Eloquent\MassPrunable`` with ``MongoDB\Laravel\Eloquent\MassPrunable``
43- in your models
55+ A breaking change is a modification in a convention or behavior in
56+ a specific version of {+odm-short+} that might prevent your application
57+ from working as expected.
4458
45- - Remove calls to not-supported methods of ``Query\Builder``: ``toSql``,
46- ``toRawSql``, ``whereColumn``, ``whereFullText``, ``groupByRaw``,
47- ``orderByRaw``, ``unionAll``, ``union``, ``having``, ``havingRaw``,
48- ``havingBetween``, ``whereIntegerInRaw``, ``orWhereIntegerInRaw``,
49- ``whereIntegerNotInRaw``, ``orWhereIntegerNotInRaw``.
59+ The breaking changes in this section are categorized by the major
60+ version releases that introduced them. When upgrading library versions,
61+ address all the breaking changes between your current version and the
62+ planned upgrade version.
63+
64+ .. _laravel-breaking-changes-v4.x:
65+
66+ Version 4.x Breaking Changes
67+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68+
69+ This library version introduces the following breaking changes:
70+
71+ - Minimum Laravel version is now 10.0. For instructions on upgrading your Laravel version,
72+ see the `Upgrade Guide <https://laravel.com/docs/10.x/upgrade>`__ in the Laravel
73+ documentation.
74+
75+ - Dependency name is now ``"mongodb/laravel-mongodb"``. Ensure that the dependency
76+ name in your ``composer.json`` file is ``"mongodb/laravel-mongodb": "^4.0"``. Then, run
77+ ``composer update``.
78+
79+ - Namespace is now ``MongoDB\Laravel\``. Ensure that you change the namespace from ``Jenssegers\Mongodb\``
80+ to ``MongoDB\Laravel\`` in your models and config files.
81+
82+ - Removes support for non-Laravel projects.
83+
84+ - Removes support for the ``$dates`` property. Ensure that you change all instances of ``$dates``
85+ to ``$casts`` in your model files.
86+
87+ - ``Model::unset($field)`` does not persist the change. Ensure that you follow all calls to
88+ ``Model::unset($field)`` with ``Model::save()``.
89+
90+ - Removes the ``Query\Builder::whereAll($column, $values)`` method. Ensure that you replace all calls
91+ to ``Query\Builder::whereAll($column, $values)`` with ``Query\Builder::where($column, 'all', $values)``.
92+
93+ - ``Query\Builder::delete()`` can delete one or all documents. Ensure that you pass only the values
94+ ``1`` or ``null`` to ``limit()``.
95+
96+ - ``whereDate()``, ``whereDay()``, ``whereMonth()``, ``whereYear()``, and ``whereTime()`` methods
97+ now use MongoDB operators on date fields.
98+
99+ - Adds the ``MongoDB\Laravel\Eloquent\MassPrunable`` trait. Ensure that you replace all instances of
100+ ``Illuminate\Database\Eloquent\MassPrunable`` with ``MongoDB\Laravel\Eloquent\MassPrunable``
101+ in your models.
102+
103+ - Removes support for the following ``Query\Builder`` methods:
104+
105+ - ``toSql()``
106+ - ``toRawSql()``
107+ - ``whereColumn()``
108+ - ``whereFullText()``
109+ - ``groupByRaw()``
110+ - ``orderByRaw()``
111+ - ``unionAll()``
112+ - ``union()``
113+ - ``having()``
114+ - ``havingRaw()``
115+ - ``havingBetween()``
116+ - ``whereIntegerInRaw()``
117+ - ``orWhereIntegerInRaw()``
118+ - ``whereIntegerNotInRaw()``
119+ - ``orWhereIntegerNotInRaw()``
0 commit comments