Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cec349a

Browse files
Merge 4.2 into 4.3 (#2919)
2 parents d98cd42 + ffecbdc commit cec349a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎docs/eloquent-models/model-class.txt‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@ type, to the Laravel ``datetime`` type.
194194
:emphasize-lines: 9-11
195195
:dedent:
196196

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+
197215
This conversion lets you use the PHP `DateTime <https://www.php.net/manual/en/class.datetime.php>`__
198216
or the `Carbon class <https://carbon.nesbot.com/docs/>`__ to work with dates
199217
in this field. The following example shows a Laravel query that uses the

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /