Laravel Eloquent get results grouped by days

前端 未结 14 653
一整个雨季
一整个雨季 2020-12-02 06:44

I currently have a table of page_views that records one row for each time a visitor accesses a page, recording the user\'s ip/id and the id of the page itself. I should add

14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 07:20

    You can filter the results based on formatted date using mysql (See here for Mysql/Mariadb help) and use something like this in laravel-5.4:

    Model::selectRaw("COUNT(*) views, DATE_FORMAT(created_at, '%Y %m %e') date")
        ->groupBy('date')
        ->get();
    

提交回复
热议问题