【发布时间】:2020-05-13 05:46:47
【问题描述】:
目前我在 laravel 中有这个雄辩的选择
$queryBooking = Booking::where('id',$id)->select('starts_at','ends_at')->first();
现在我想将特定格式放入starts_at 和ends_at 使用这种格式Y-m-d
数据应显示为2020-05-29(Y-m-d)
如何使用 laravel eloquent 做到这一点?
更新
尝试了 spiny 的答案做了一些修改。
$queryBooking = Booking::where('id',$id)->select('starts_at','ends_at')->first();
$booking = PropertyBooking::where('property_id',$queryBooking->property_id)
->selectRaw(
'DATE_FORMAT(`starts_at`, "%Y-%m-%d") AS `starts_at`, DATE_FORMAT(`ends_at`, "%Y-%m-%d") AS `ends_at`'
)->get();
return view('admin.pages.property_request.edit', compact('property_request','booking'));
在我的刀片中尝试使用 js 记录它是这样说的
【问题讨论】:
-
date('Y-m-d',strtotime($queryBooking->starts_at))试试这个方法。 -
它会给我预期的输出,但我正在尝试以雄辩的方式工作..