为什么我要从模型属性中获取碳实例?

Why am I getting a carbon instance from a model attribute?

我有 collection 个 riv_queries。

$riv_queries = RivQuery::where('id', Auth::user()->id)->first();
RivQuery {#157 ▼

#attributes: array:12 [▼
    "id" => 88
    "riv_from" => "2019-10-15"
    "riv_to" => "2019-10-15"
    "department_id" => 109
    "type_id" => 0
    "record_type_id" => 1
    "cal_year" => 2018
    "accordion" => 0
    "city_id" => 0
    "region_id" => 8
    "prov_id" => 837
    "tx_date" => "2019-10-15"
  ]

My problem is whenever I want to get 'riv_to' or 'riv_from' I always get this as a result

dd($riv_queries->riv_to);
Carbon @1571068800 {#638 ▼
  date: 2019-10-15 00:00:00.0 Asia/Manila (+08:00)
}

But i only expect result like this

"2019-10-15"

我做错了什么?

试试这个:

dd((字符串)$riv_queries->riv_to);

$dates 属性 中定义的任何字段自动转换为 CarbonDate Mutators.

By default, Eloquent will convert the created_at and updated_at columns to instances of Carbon, which extends the PHP DateTime class and provides an assortment of helpful methods. You may add additional date attributes by setting the $dates property of your model

您还可以将 Carbon 实例格式化为 string,例如:

$riv_queries->riv_to->format('Y-M-d');