From ffecbdc7bc6a1f74603ecb9b7360849999fdd2bf Mon Sep 17 00:00:00 2001 From: Nora Reidy Date: Fri, 26 Apr 2024 14:14:37 -0400 Subject: [PATCH] DOCSP-37112: Casts() method info (#2901) Adds an admonition about Laravel 11 casts changes --- docs/eloquent-models/model-class.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/eloquent-models/model-class.txt b/docs/eloquent-models/model-class.txt index 5542b35ea..f1d1fbdda 100644 --- a/docs/eloquent-models/model-class.txt +++ b/docs/eloquent-models/model-class.txt @@ -194,6 +194,24 @@ type, to the Laravel ``datetime`` type. :emphasize-lines: 9-11 :dedent: +.. 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 performs the same + conversion as the preceding example by using a ``casts()`` method: + + .. code-block:: php + + protected function casts(): array + { + return [ + 'discovery_dt' => 'datetime', + ]; + } + + 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 in this field. The following example shows a Laravel query that uses the