首页 > 解决方案 > Laravel 查找存在于 CarbonPeriod 中的记录

问题描述

我在此之后的 2 个日期之间创建了一个 CarbonPeroid 对象

$period = CarbonPeriod::create('2018-06-14', '2018-06-20');

现在我想过滤该 $period 对象中存在的所有帖子。

我试过这样但它不起作用

        $posts = Posts::whereBetween(
            'created_at', [$period]
        )->get();

任何帮助表示赞赏。

标签: laravellaravel-8php-carbon

解决方案


提供CarbonPeriod对象的开始和结束日期。

$posts = Posts::whereBetween(
        'created_at', [$period->startDate, $period->endDate]
    )->get();

推荐阅读