回调方法/匿名函数,返回 Y-m-d 格式日期 'created_at' => 'getCurrentDate', ]; // protected $update = [ // // 字段名 => 回调方法/匿名函数,返回 Y-m-d 创建日期 // 'updated_at' => function() { return date('Y-m-d H:i:s'); } // ]; // 自定义方法,返回当前日期 protected function getCurrentDate() { return date('Y-m-d H:i:s'); } // 表达式对应分类 public function category() { return $this->belongsTo(ExpressionCategory::class, 'category_id'); } public function getImgAttribute($value) { return ensureUrl($value); } }