'datetime:Y-m-d H:i:s', // 指定序列化格式 'created_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式 ]; /** * 重新格式化时间 * @param DateTimeInterface $date * @return string */ protected function serializeDate(DateTimeInterface $date): string { return $date->format(Carbon::parse($date)->toDateTimeString()); } /** * 客户的标签 */ public function tags() { return $this->belongsToMany(Tag::class, 'crm_customer_tag', 'customer_id', 'tag_id') ->withTimestamps(); // 如果需要记录关联时间 } // 定义与 变更历史 的一对多关系 public function his() { return $this->hasMany(CustomerHis::class, 'customer_id', 'id'); } // 定义反向多对一关联 public function user() { return $this->belongsTo(User::class, 'user_id', 'id'); } }