Laravel ORM模型
# 模型属性
# $table-自定义表名
protected $table = 'user';
1
# $primaryKey-表主键名称
protected $primaryKey = 'flight_id'; // 默认转换为一个intger类型
1
# $incrementing-指定主键是不是自增
public $incrementing = false;
1
# $keyType-自增ID的数据类型
protected $keyType = 'string';
1
# $timestamps-时间戳
是否启用时间戳维护,管理created_at
和updated_at
字段
protected $timestamps = false;
1
# $dateFormat-日期属性存储方式
protected $dateFormat = 'U';
1
# CREATED_AT/UPDATED_AT-自定义存储时间戳字段名
const CREATED_AT = 'creation_date';
const UPDATED_AT = 'updated_date';
1
2
2
# $connection-数据库链接名
protected $connection = 'sqlite';
1
# $append-追加字段
protected $appends = [
'status_text'
];
1
2
3
2
3
# $attributes-默认属性值
protected $attributes = [
'delayed' => false,
];
1
2
3
2
3
# $hidden-隐藏字段
protected $hidden = [
'password'
];
1
2
3
2
3
# $visible-显示字段
protected $visible = ['first_name', 'last_name'];
1
# $casts-类型转换
详细请查看:Laravel ORM属性修改器
protected $casts = [
'is_admin' => 'boolean',
];
1
2
3
2
3
可用类型有:
- array
- boolean
- collection
- date
- datetime
- decimal:
<digits>
- double
- encrypted
- encrypted:array
- encrypted:collection
- encrypted:object
- float
- integer
- object
- real
- string
- timestamp
# 模型方法
上次更新: 2023/12/22, 10:33:26