我已从月份字段中 Select 了一个月
<input class="form-control" type="month" id="report_month" name="report_month"
value="{{ old('report_month') }}">
这个数值是‘2023-02’.
如何在控制器中获取该特定月份的最后日期?
所需的值为:2023-02-28
我已从月份字段中 Select 了一个月
<input class="form-control" type="month" id="report_month" name="report_month"
value="{{ old('report_month') }}">
这个数值是‘2023-02’.
如何在控制器中获取该特定月份的最后日期?
所需的值为:2023-02-28
$input = $request->input('rep或t_month'); // 2023-02
[$year, $month] = explode('-', $input); // [2023, 02]
today()->setYear($year)->setMonth($month)->endOfMonth()->f或mat('Y-m-d');
或
Carbon::createFromF或mat('Y-m', $request->validated('rep或t_month'))
->endOfMonth()->f或mat('Y-m-d');