From f15d4ade4bdce6e112f8abc06e8e4b51747436b8 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 22 Apr 2024 16:24:12 -0400 Subject: [PATCH 1/5] DOCSP-37112: Casts() method info --- docs/fundamentals/write-operations.txt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/fundamentals/write-operations.txt b/docs/fundamentals/write-operations.txt index 242d4e941..e02968020 100644 --- a/docs/fundamentals/write-operations.txt +++ b/docs/fundamentals/write-operations.txt @@ -49,8 +49,21 @@ The write operations in this guide reference the following Eloquent model class: in the Eloquent Model Class documentation. The ``$casts`` attribute instructs Laravel to convert attributes to common - data types. To learn more, see `Attribute Casting `__ - in the Laravel documentation. + data types. In Laravel 11, you can define a ``casts()`` method instead of using + the ``$casts`` attribute. The following code converts the ``$casts`` attribute + specified in the sample model class to a ``casts()`` method: + + .. code-block:: php + + protected function casts(): array + { + return [ + 'performanceDate' => 'datetime', + ]; + } + + To learn more, see the `Model Casts `__ + page on the Laravel News website. .. _laravel-fundamentals-insert-documents: From 06ee3ba0e96252f2039d2b03cf446ee70bb7a022 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 22 Apr 2024 16:34:55 -0400 Subject: [PATCH 2/5] move tip --- docs/eloquent-models/model-class.txt | 18 ++++++++++++++++++ docs/fundamentals/write-operations.txt | 17 ++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/docs/eloquent-models/model-class.txt b/docs/eloquent-models/model-class.txt index 5542b35ea..6af580b42 100644 --- a/docs/eloquent-models/model-class.txt +++ b/docs/eloquent-models/model-class.txt @@ -204,6 +204,24 @@ less than three years ago: Planet::where( 'discovery_dt', '>', new DateTime('-3 years'))->get(); +.. tip:: Casts in Laravel 11 + + In Laravel 11, you can define a ``casts()`` method to specify data type conversions + instead of using the ``$casts`` attribute. The following code converts + the ``$casts`` attribute in the ``Planet`` model class to a ``casts()`` method: + + .. code-block:: php + + protected function casts(): array + { + return [ + 'discovery_dt' => 'datetime', + ]; + } + + To learn more, see the `Model Casts `__ + announcement page on the Laravel News website. + To learn more about MongoDB's data types, see :manual:`BSON Types ` in the MongoDB server docs. diff --git a/docs/fundamentals/write-operations.txt b/docs/fundamentals/write-operations.txt index e02968020..242d4e941 100644 --- a/docs/fundamentals/write-operations.txt +++ b/docs/fundamentals/write-operations.txt @@ -49,21 +49,8 @@ The write operations in this guide reference the following Eloquent model class: in the Eloquent Model Class documentation. The ``$casts`` attribute instructs Laravel to convert attributes to common - data types. In Laravel 11, you can define a ``casts()`` method instead of using - the ``$casts`` attribute. The following code converts the ``$casts`` attribute - specified in the sample model class to a ``casts()`` method: - - .. code-block:: php - - protected function casts(): array - { - return [ - 'performanceDate' => 'datetime', - ]; - } - - To learn more, see the `Model Casts `__ - page on the Laravel News website. + data types. To learn more, see `Attribute Casting `__ + in the Laravel documentation. .. _laravel-fundamentals-insert-documents: From 4346dd5711d3a15da36741ca02cf767b631eee09 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 22 Apr 2024 16:38:04 -0400 Subject: [PATCH 3/5] reformat --- docs/eloquent-models/model-class.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/eloquent-models/model-class.txt b/docs/eloquent-models/model-class.txt index 6af580b42..deeb0a825 100644 --- a/docs/eloquent-models/model-class.txt +++ b/docs/eloquent-models/model-class.txt @@ -194,16 +194,6 @@ type, to the Laravel ``datetime`` type. :emphasize-lines: 9-11 :dedent: -This conversion lets you use the PHP `DateTime `__ -or the `Carbon class `__ to work with dates -in this field. The following example shows a Laravel query that uses the -casting helper on the model to query for planets with a ``discovery_dt`` of -less than three years ago: - -.. code-block:: php - - Planet::where( 'discovery_dt', '>', new DateTime('-3 years'))->get(); - .. tip:: Casts in Laravel 11 In Laravel 11, you can define a ``casts()`` method to specify data type conversions @@ -221,6 +211,16 @@ less than three years ago: To learn more, see the `Model Casts `__ announcement page on the Laravel News website. + +This conversion lets you use the PHP `DateTime `__ +or the `Carbon class `__ to work with dates +in this field. The following example shows a Laravel query that uses the +casting helper on the model to query for planets with a ``discovery_dt`` of +less than three years ago: + +.. code-block:: php + + Planet::where( 'discovery_dt', '>', new DateTime('-3 years'))->get(); To learn more about MongoDB's data types, see :manual:`BSON Types ` in the MongoDB server docs. From 482500de23e102ad64005e8c997ece81adc52d7b Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 23 Apr 2024 10:24:16 -0400 Subject: [PATCH 4/5] RR feedback --- docs/eloquent-models/model-class.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/eloquent-models/model-class.txt b/docs/eloquent-models/model-class.txt index deeb0a825..db906c3d9 100644 --- a/docs/eloquent-models/model-class.txt +++ b/docs/eloquent-models/model-class.txt @@ -197,8 +197,8 @@ type, to the Laravel ``datetime`` type. .. tip:: Casts in Laravel 11 In Laravel 11, you can define a ``casts()`` method to specify data type conversions - instead of using the ``$casts`` attribute. The following code converts - the ``$casts`` attribute in the ``Planet`` model class to a ``casts()`` method: + instead of using the ``$casts`` attribute. The following code performs the same + conversion as the preceding example by using a ``casts()`` method: .. code-block:: php @@ -209,8 +209,8 @@ type, to the Laravel ``datetime`` type. ]; } - To learn more, see the `Model Casts `__ - announcement page on the Laravel News website. + To learn more, see the `Model Casts are moving to methods in Laravel 11 `__ + article on the Laravel News website. This conversion lets you use the PHP `DateTime `__ or the `Carbon class `__ to work with dates From ec18522065ee773cf871a94a4c078e25b1d7c0cd Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 26 Apr 2024 11:28:57 -0400 Subject: [PATCH 5/5] JT feedback --- docs/eloquent-models/model-class.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/eloquent-models/model-class.txt b/docs/eloquent-models/model-class.txt index db906c3d9..f1d1fbdda 100644 --- a/docs/eloquent-models/model-class.txt +++ b/docs/eloquent-models/model-class.txt @@ -209,8 +209,8 @@ type, to the Laravel ``datetime`` type. ]; } - To learn more, see the `Model Casts are moving to methods in Laravel 11 `__ - article on the Laravel News website. + To learn more, see `Attribute Casting `__ + in the Laravel documentation. This conversion lets you use the PHP `DateTime `__ or the `Carbon class `__ to work with dates