File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,24 @@ type, to the Laravel ``datetime`` type.
194
194
:emphasize-lines: 9-11
195
195
:dedent:
196
196
197
+ .. tip:: Casts in Laravel 11
198
+
199
+ In Laravel 11, you can define a ``casts()`` method to specify data type conversions
200
+ instead of using the ``$casts`` attribute. The following code performs the same
201
+ conversion as the preceding example by using a ``casts()`` method:
202
+
203
+ .. code-block:: php
204
+
205
+ protected function casts(): array
206
+ {
207
+ return [
208
+ 'discovery_dt' => 'datetime',
209
+ ];
210
+ }
211
+
212
+ To learn more, see `Attribute Casting <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-mutators#attribute-casting>`__
213
+ in the Laravel documentation.
214
+
197
215
This conversion lets you use the PHP `DateTime <https://www.php.net/manual/en/class.datetime.php>`__
198
216
or the `Carbon class <https://carbon.nesbot.com/docs/>`__ to work with dates
199
217
in this field. The following example shows a Laravel query that uses the
You can’t perform that action at this time.
0 commit comments