fantasyspot.blogg.se

Mysql cast
Mysql cast









mysql cast

The encrypted cast will encrypt a model's attribute value using Laravel's built-in encryption features. To accomplish this, you may specify the attribute and enum you wish to cast in your model's $casts property array: Typically, this will be the timezone specified in your application's timezone configuration option.Įloquent also allows you to cast your attribute values to PHP Enums. If a custom format is applied to the date or datetime cast, such as datetime:Y-m-d H:i:s, the inner timezone of the Carbon instance will be used during date serialization. Consistently using the UTC timezone throughout your application will provide the maximum level of interoperability with other date manipulation libraries written in PHP and JavaScript.

mysql cast

You are strongly encouraged to always use this serialization format, as well as to store your application's dates in the UTC timezone by not changing your application's timezone configuration option from its default UTC value. All attribute accessor / mutator methods must declare a return type-hint of Illuminate\Database\Eloquent\Casts\Attribute:īy default, the date and datetime casts will serialize dates to a UTC ISO-8601 date string ( YYYY-MM-DDTHH:MM:SS.uuuuuuZ), regardless of the timezone specified in your application's timezone configuration option. The accessor will automatically be called by Eloquent when attempting to retrieve the value of the first_name attribute. In this example, we'll define an accessor for the first_name attribute. This method name should correspond to the "camel case" representation of the true underlying model attribute / database column when applicable. To define an accessor, create a protected method on your model to represent the accessible attribute. Or, you may want to convert a JSON string that is stored in your database to an array when it is accessed via your Eloquent model.Īn accessor transforms an Eloquent attribute value when it is accessed.

mysql cast

For example, you may want to use the Laravel encrypter to encrypt a value while it is stored in the database, and then automatically decrypt the attribute when you access it on an Eloquent model. Accessors, mutators, and attribute casting allow you to transform Eloquent attribute values when you retrieve or set them on model instances.











Mysql cast