laravel model 层

model层中 created_at ,updated_at  

$timestamp=false; 

官方地址

其他参考地址

2) model 层中指定场景使用rule; rules

3) model 层中添加额外字段 $appends : 场景再现, 数据库中有 id,name;但是没有性别, 使用模型后,想额外添加一下性别sex怎么办??? 

解决方案: model层中使用

//model 中代码
    protected $appends = ['sex','age'];
    public function getSexAttribute()
    {
        return '男';
    }

    public function getAgeAttribute()
    {
        return '18岁';
    }

//controller  中代码,3中方式都可以把sex,age ,追加进来
        $model = Student::find(1);
        print_r($model->append('sex','age')->toArray());
        print_r(json_encode($model,JSON_UNESCAPED_UNICODE));

        $model = Student::query()->where('id', 1)->first();
        print_r($model->toArray());exit();

03) 获取model层中表名字

dd(Student::getModel()->getTable());  //方法一
 
dd((new Student())->getTable());   //方法二
原文地址:https://www.cnblogs.com/dafei4/p/13812880.html