Laravel Model常用属性


$table = ‘应当操作的表名’;
$primaryKey= ‘主键’;
$timestamps = false;//是否创建crearte_at与update_at字段
$fillable = [ ‘可批量填充的字段’];
$guarded= [ ‘不可批量填充的字段’];
$hidden = [ ‘模型转换为数组时应当隐藏的字段’];
$visable = [‘模型转换为数组时应当显示的字段’];
$appends = [ ‘模型转换为数组时应当追加的虚拟字段’ // 例如访问器];
$with = [ ‘应预加载的关联关系’,];
$attributes= [ ‘字段名’ => ‘字段默认值’];
$casts= [‘字段名’ => ‘数据类型转换的目标类型’];
$dates = [ ‘应当被转换为日期时间的字段’];
$touches = [ ‘模型更新时应当一并更新的关联关系’];
$dispatchesEvents = [ ‘模型事件’=>’自定义事件’(设置模型事件与自定义事件的映射)];

评论被关闭.