模型中的 $casts 属性提供了一个便利的方法来将属性转换为常见的数据类型。$casts 属性应是一个数组,且数组的键是那些需要被转换的属性名称,值则是你希望转换的数据类型。支持转换的数据类型有: integer, real, float,double, decimal:<digits>,string, boolean, object, array,collection, date, datetime, 和 timestamp。 当需要转换为 decimal 类型时,你需要定义小数位的个数,如: decimal:2
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SoftwareVersion extends Model
{
protected $casts = [
'software_ids' => 'array',
];
}
?>